Docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 636d261 · Browse files · 1 file·+61 added−0 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+61 added−0 removed
- other:+61 added−0 removed
Provenance
- Commit
744bfa8- Tree
899fd4c- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
636d261
1 file changed+61 added−0 removed
modified:lib/express.core.js+61 added
128 unmodified lines129 return value ? this.response.headers[name] = value :130 this.response.headers[name]131 },132 133+ /**134+ * Return param _key_'s value or _defaultValue_ when135+ * the param has not been set.136+ *137+ * @param {string} key138+ * @param {mixed} defaultValue139+ * @return {mixed}140+ * @api public141+ */142+ 143 param : function(key, defaultValue) {144 return this.request.uri.params[key] || defaultValue145 },146 147+ /**148+ * Normalize a path. Strips trailing / leading whitespace149+ * and slashes ('/').150+ *151+ * @param {string} path152+ * @return {string}153+ * @api public154+ */155+ 156 normalizePath : function(path) {157 return path.replace(/^(\s|\/)*|(\s|\/)*$/g, '')158 },159 8 unmodified lines168 contentsOf : function(body) {169 return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]170 },171 172+ /**173+ * Dump _object_.174+ *175+ * @param {mixed} object176+ * @api public177+ */178+ 179 dump : function(object) {180 puts(JSON.stringify(object))181 },182 183+ /**184+ * Attept to match and call a route for 185+ * the given _request_, returning the data186+ * returned by the route callback.187+ *188+ * @param {object} request189+ * @return {mixed}190+ * @api public191+ */192+ 193 callRouteFor : function(request) {194 // method GET195 // uri.directory196 // uri.path4 unmodified lines201 var route = this.findRouteFor(request) || this.defaultRoute202 return eval('function(){ with (Express){' + Express.contentsOf(route.callback) + '}}')()203 },204 205+ /**206+ * Attemp to find and return a route matching _request_.207+ *208+ * @param {object} request209+ * @return {object}210+ * @api public211+ */212+ 213 findRouteFor : function(request) {214 for (var i = 0, len = this.routes.length; i < len; ++i)215 if (this.routeMatches(this.routes[i], request))216 return this.routes[i]217 },218 219+ /**220+ * Check if _route_ matches _request_221+ *222+ * @param {object} route223+ * @param {object} request224+ * @return {bool}225+ * @api public226+ */227+ 228 routeMatches : function(route, request) {229 if (route.method != request.method.toLowerCase()) return false230 switch (route.path.constructor) {231 case String: return route.path == request.uri.path2 unmodified lines234 return Express.captures = captures235 }236 },237 238+ /**239+ * Return a routing function for _method_.240+ *241+ * @param {string} method242+ * @return {function}243+ * @api private244+ */245+ 246 routeFunctionFor : function(method) {247 return function(path, callback) {248 if (typeof path == 'string') path = Express.normalizePath(path)249 Express.routes.push({27 unmodified lines