Skip to content
Myr

Changed `req.param()` to check route first

Before adoption: this commit came in with the history the project adopted, so no landing records it.

body / query-string taking precedence is a little sketchy but you should use this method sparingly, think of it as PHPs $_REQUEST

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 1763b07 · Browse files · 1 file+4 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−4 removed

  • other:+4 added−4 removed

1 file+4 added−4 removed

modified:lib/request.js+4 added-4 removed
206 unmodified lines
207208/**209 * Return the value of param `name` when present or `defaultValue`.210 *211 * - Checks body params, ex: id=12, {"id":12}211 * - Checks route placeholders, ex: _/user/:id_212 * - Checks body params, ex: id=12, {"id":12}213 * - Checks query string params, ex: ?id=12214 *215 * To utilize request bodies, `req.body`216 * should be an object. This can be done by using
5 unmodified lines
222 * @api public223 */224225req.param = function(name, defaultValue){226 // req.body227 if (this.body && undefined !== this.body[name]) return this.body[name];228226 // route params227 if (this.params228 && this.params.hasOwnProperty(name)229 && undefined !== this.params[name]) {230 return this.params[name]; 231 }232233 // req.body234 if (this.body && undefined !== this.body[name]) return this.body[name];235236 // query-string237 if (undefined !== this.query[name]) return this.query[name]; 238239 return defaultValue;
175 unmodified lines