named-routes icon indicating copy to clipboard operation
named-routes copied to clipboard

Allow to pass name/options as third argument in standalone mode

Open damianstasik opened this issue 7 years ago • 4 comments

This PR changes how router.add works:

// Name after route path + no need for an array when using more than one middleware
router.add('get', '/user/:id', 'user', isAuthenticated, someOtherMiddleware, (req, res) => {
    res.send('Hello!');
});

// ... but, you still can use array
router.add('get', '/post/:id', 'post', [someOtherMiddleware, (req, res) => {
    res.send('Hello!');
}]);

// Have more than one option? Just pass an object before your middlewares
router.add('get', '/page/:id', {name: 'page', caseSensitive: true}, (req, res) => {
    res.send('Hello!');
});

// Don't want to use a name? Sure, just ditch it
router.add('get', '/category/:id', someOtherMiddleware, (req, res) => {
    res.send('Hello!');
});

Closes #25

damianstasik avatar Aug 28 '16 16:08 damianstasik

Thanks for putting together this PR! I believe this PR also changes the behaviour of router.add so that it in addition to an array of callbacks/middlewares, it can now take any length of arguments. I think I prefer that behaviour, so now there are two options:

  1. Update the tests to include cases with multiple callbacks without using arrays and update the documentation
  2. Extract this change for a second PR What do you think?

alubbe avatar Aug 29 '16 05:08 alubbe

Thanks for quick reply! I'll add a few new test cases and update the docs accordingly.

damianstasik avatar Aug 29 '16 05:08 damianstasik

Sorry for the delay, but the missing tests are now included. @alubbe, could you verify if everything is now good? Would it be okay if I would rewrite the tests (add more cases and split existing into smaller groups)?

damianstasik avatar Sep 30 '16 10:09 damianstasik

Could you please update the docs, as well? The tests are a left-over from the original fork and are in serious need of a makeover. Aside from new cases and smaller groups, the whole thing should really use describe and it instead of that object notation. So that would be two PRs - one converting the current tests into something more modern and another one adding / rewriting them.

alubbe avatar Oct 03 '16 13:10 alubbe