bunsvr / router

A blazing-fast router for Stric

Home Page:https://stricjs.netlify.app/#/basic/routing/main

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some paths hit 404 with certain paths configured

karl-run opened this issue · comments

commented

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.

commented

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%
commented

Yea some issues with composing
image
This part should start at 1 not 2

commented

This seems to be an issue with multiple inerts

commented

Oh wait the node tree is incorrectly fixed

commented

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

commented

@karl-run Now it works normally in 4.0.4

commented

One more thing I recommend when using Stric (and other frameworks as well)
Use sync handlers as much as possible and minimizing memory allocations (creating functions and objects) @karl-run