Replacing a parameter in the current route #53

Open
scottkf opened this Issue Sep 4, 2012 · 1 comment

Comments

Projects
None yet
2 participants

scottkf commented Sep 4, 2012

Is there an easy way to accomplish this without reusing the code in the prototype.run function? It doesn't seem like it, but I could be blind! I'm trying to programmatically redirect something, but change a parameter.

Owner

olivernn commented Sep 7, 2012

A request has a redirect method already see the docs.

I'm not entirely sure what you mean by "programmatically redirect something, but change a parameter", do you want to re-run the same route but add a parameter if it is missing? This could be achieved with some route middleware, e.g.

var paramChanger = function (req, next) {
  req.params.foo += 1
  next(req)
}

this.get('/somepath', paramChanger, function (req) {
  // do whatever with req.params.foo now
})

More on this in the docs. This wouldn't re-run the route but do the massaging of the params before your route is run…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment