Skip to content

Parametric route /:id incorrectly matches / when no static route is registered #422

Description

@mahendra7041

I have this setup:

import http from "http";
import FindMyWay from "find-my-way";

const router = FindMyWay({
  defaultRoute: (req, res) => {
    res.statusCode = 404;
    res.end(JSON.stringify({ message: "Not Found" }));
  },
});

router.on("GET", "/:id", (req, res, params) => {
  res.end(JSON.stringify(params));
});

const server = http.createServer((req, res) => {
  router.lookup(req, res);
});

server.listen(3000);

When I hit /, I expect defaultRoute to handle it since there's no / route registered. Instead my /:id handler fires with params.id = undefined.

curl http://localhost:3000
# Expected: 404 from defaultRoute
# Actual:   {} — /:id handler called with id = undefined

The only workaround I found is manually registering a / route, which feels wrong when defaultRoute already exists for this purpose.

  • find-my-way version: ^9.5.0
  • Node.js version: v24.14.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions