Skip to content
Myr

Make route params request specific

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

authored by visionmedia · committed by visionmedia · parent 37948d8 · Browse files · 3 files+30 added−30 removed
This commit

State

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

Diff stats

3 files+30 added−30 removed

  • other:+30 added−30 removed

3 files+30 added−30 removed

modified:examples/app.js+22 added-10 removed
modified:lib/express/core.js+7 added-19 removed
110 unmodified lines
111112Router = Class({113 114 /**115 * Parameter hash.116 */117 118 params: {},119 120 /**121 * Route match captures array.122 */123 124 captures: [],125 126 /**115 * Route the given _request_, returning116 * the value returned by Route#run()117 *118 * @param {object} request
4 unmodified lines
123 route: function(request){124 this.request = request125 var route = this.matchingRoute()126 if (route)139 return route.run(this.captures.slice(1))127 return route.run(this.request.captures.slice(1))128 else if (accepts('html') && set('helpful 404'))129 halt(404, require('express/pages/not-found').render())130 else131 halt()
23 unmodified lines
155 */156157 match: function(route) {158 if (this.request.method.toLowerCase() == route.method)171 if (this.captures = this.request.uri.path.match(route.path)) {159 if (this.request.captures = this.request.uri.path.match(route.path)) {160 this.mapParams(route)161 return true162 }163 },164 165 /**178 * Map #captures to #params based on the166 * Map #request.captures to #request.params based on the167 * given _route_ keys.168 *169 * @param {Route} route170 * @api private
1 unmodified line
172 173 mapParams: function(route) {174 var self = this175 $(route.keys).each(function(key, i){188 self.params[key] = self.captures[++i]176 self.request.params[key] = self.request.captures[++i]177 })178 }179})180
55 unmodified lines
236 */237 238 route: function(request, response){239 var body 252 response.headers = {}240 response.headers = {}, request.params = {}241 this.request = request, this.response = response242 this.request.uri.path = normalizePath(request.uri.path)243 this.request.uri.params = parseNestedParams(request.uri.params)244 this.request.uri.post =
1 unmodified line
246 parseParams(request.body) :247 {}248 trigger('request')249 try {262 if (typeof (body = Express.router.route(request)) == 'string')250 if (typeof (body = (new Express.router).route(request)) == 'string')251 halt(200, body)252 }253 catch (e) {254 if (e instanceof ExpressError)
32 unmodified lines
287 routes: [],288 plugins: [],289 settings: {},290 server: new Server,303 router: new Router291 router: Router292}293294// --- Defaults295
3 unmodified lines
modified:lib/express/helpers.js+1 added-1 removed
96 unmodified lines
97 * @api public98 */99100exports.param = function(key) {101 return Express.router.params[key] ||101 return Express.server.request.params[key] ||102 Express.server.request.uri.post[key] ||103 Express.server.request.uri.params[key]104}105
180 unmodified lines