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

Adding generic hooks doesn't have an effect on existing routes #313

Open
epaezrubio opened this issue May 3, 2022 · 0 comments
Open

Adding generic hooks doesn't have an effect on existing routes #313

epaezrubio opened this issue May 3, 2022 · 0 comments

Comments

@epaezrubio
Copy link

The following snippet will correctly print before hook followed by route handler:

router.hooks({
  before: (next) => {
    console.log('before hook');
    next();
  },
});

router.on('/', () => {
  console.log('route handler');
});

However, the following will just print route handler:

router.on('/', () => {
  console.log('route handler');
});

router.hooks({
  before: (next) => {
    console.log('before hook');
    next();
  },
});

Furthermore, if generic hooks are registered before and after route handlers are registered, then only the first routes will be affected by the global hooks.

Is this a design decision or a bug? It creates a complicated scenario, where the declarations need to be carefully called in the right order, and where you are limited by the initial declaration of the hooks. I can imagine many use cases where the library consumer would want to override the generic hooks.

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

No branches or pull requests

1 participant