delvedor / find-my-way

A crazy fast HTTP router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Host constraint breaks with 32 handlers

valeneiko opened this issue · comments

If I add 32 handlers with host constraints, then none of the handlers will match and no errors are thrown.

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

const N = 32;

for (let i = 0; i < N; i++) {
  const host = `h${i.toString().padStart(2, '0')}`;
  router.on('GET', '/', { constraints: { host } }, () => { });
}

const result = router.find('GET', '/', { host: 'h01' });
console.log(result); // --> null

If I change N to 33 then error is thrown from the code below:

if (!isMergedTree && this.handlers.length >= 32) {
throw new Error('find-my-way supports a maximum of 32 route handlers per node when there are constraints, limit reached')
}

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