Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcard bug #151

Closed
dylannil opened this issue May 17, 2020 · 1 comment
Closed

Wildcard bug #151

dylannil opened this issue May 17, 2020 · 1 comment

Comments

@dylannil
Copy link
Contributor

dylannil commented May 17, 2020

const http = require('http');
const router = require('find-my-way')();

router.on('OPTIONS', '/*', (req, res, params) => {
  res.end('{"hello": "world"}');
});
router.on('OPTIONS', '/obj/*', (req, res, params) => {
  res.end('{"hello": "wildcard"}');
});
router.on('GET', '/obj/:id', (req, res, params) => {
  res.end('{"hello": "paramtric"}');
});

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

server.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on: http://localhost:3000');
  // test
  const req = http.request({
    host: 'localhost',
    port: 3000,
    method: 'OPTIONS',
    path: '/obj/params'
  }, res => {
    const chunks = [];
    res.on('data', chunk => chunks.push(chunk));
    res.on('end', () => {
      const data = Buffer.concat(chunks).toString();
      console.log(data); // result string 
    });
  });
  req.end();
});

As I expect,the result data should be {"hello": "wildcard"}.

Actually, it is {"hello": "world"}.

It seems something wrong with Node.prototype.{findChild, findVersionChild}:

child = this.children[':'] || this.children['*']
@mcollina
Copy link
Collaborator

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants