Some paths hit 404 with certain paths configured
karl-run opened this issue · 7 comments
I was migrating a express app to @stricjs/router when I found this strange issue.
Here's a minimal repro server:
import { Router } from '@stricjs/router';
const router = new Router();
router.get('/dekoratoren/api/sok', async (req: Request) => {
return new Response('OK sok');
});
router.get('/footer', async (req) => {
return new Response('OK footer');
});
router.get('/header', async (req) => {
return new Response('OK header');
});
router.get('/data/:key', async (req) => {
return new Response('OK data ' + req.params.key);
});
router.get('/', async (req) => {
return new Response('OK root');
});
router.use(
404,
(req) =>
new Response(`Unable to find: ${req.url}`, {
status: 404,
}),
);
export default router;
The routes /
, /header
and /footer
work as expected, but /data/:key
and /dekoratoren/api/sok
both return 404. However, if you remove either of those two routes, the other one starts working.
Here's a quick script to hit all the endpoints:
curl http://localhost:3000/
echo
curl http://localhost:3000/header
echo
curl http://localhost:3000/footer
echo
curl http://localhost:3000/data/test-id
echo
curl http://localhost:3000/dekoratoren/api/sok
Output with all routes configured:
OK root
OK header
OK footer
Unable to find: http://localhost:3000/data/test-id
Unable to find: http://localhost:3000/dekoratoren/api/sok%
Output with /data/:id
removed:
OK root
OK header
OK footer
Unable to find: http://localhost:3000/data/test-id
OK sok%
Output with /dekoratoren/api/sok
removed:
OK root
OK header
OK footer
OK data test-id
Unable to find: http://localhost:3000/dekoratoren/api/sok%
This seems to be an issue with multiple inerts
Oh wait the node tree is incorrectly fixed
I fixed it
The reason this occured is that I forgot to call fixNode
Thank you for pointing out the issue
Soon enough I will have a patch, 4.0.4
I will notify you and close the issue