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

Router: add parameter handling to middleware #1935

Merged
merged 1 commit into from
Feb 25, 2014

Conversation

defunctzombie
Copy link
Contributor

Middleware (.use) can now specify parameter arguments to trigger
Router.param loading. This is handy if you want to .use additional
routers but need to load certain objects before the mounted middleware
runs.

This will resolve #696

Middleware (.use) can now specify parameter arguments to trigger
Router.param loading. This is handy if you want to `.use` additional
routers but need to load certain objects before the mounted middleware
runs.
defunctzombie added a commit that referenced this pull request Feb 25, 2014
Router: add parameter handling to middleware
@defunctzombie defunctzombie merged commit caa25b5 into master Feb 25, 2014
@dougwilson dougwilson deleted the router-params-middleware branch May 31, 2014 03:46
rlidwka pushed a commit to rlidwka/express that referenced this pull request Aug 6, 2014
…leware

Router: add parameter handling to middleware
@ismailarilik
Copy link

I cannot still use route parameters with app.use on Express 4.16.2.

I have a statement like this:

app.use('/course-sessions/:courseSessionId/chapter-sessions', chapterSessionsRouter)

And, in chapter sessions router:

// Index.
router.get('/', ...resource.indexMethods)

When I got '/course-sessions/0/chapter-sessions/', I have 404.

Then I am trying a statement like this:

app.get('/course-sessions/:courseSessionId/chapter-sessions', ...chapterSessionResource.indexMethods)

Now I have the result I want. So route parameters still don't work with app.use. Please fix me if I am wrong but didn't this pull request solve this issue?

@paulrad
Copy link

paulrad commented Mar 21, 2018

Try to invoke your Router like this

const router = new Router({mergeParams: true})

@remotevision
Copy link

remotevision commented Apr 12, 2019

Try to invoke your Router like this

const router = new Router({mergeParams: true})

Did this work for others? I did not see a difference and still receiving a 404.
"express": "^4.16.4"

/routes/index.js
app.use('/index', indexManager);

/routes/indexManager+v1.js

const router = new express.Router({ mergeParams: true });
module.exports = router;

router.put('/:id', (req, res) => {
  res.send('Got a PUT request at /index');
});

I also tried adding this per their example, but still returns a 404.

router.param('id', function (req, res, next, value) {
  console.log('CALLED ONLY ONCE with', value);
  next();
});

EDIT:
Never mind, this was a Firebase Function routing problem for me. Anyone else using Firebase Functions, simply having a rewrite of just /path is not sufficient for url params. Need to have /path/**

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 this pull request may close these issues.

app.use('/:param', paramApp) not supported
4 participants