Skip to content
Myr

application.js

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent adf7124 · Browse files · 3 files+586 added−586 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+586 added−586 removed

  • other:+586 added−586 removed

3 files+586 added−586 removed

added:lib/application.js+585 added
12/*!3 * Express - proto4 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>5 * MIT Licensed6 */78/**9 * Module dependencies.10 */1112var connect = require('connect')13 , Router = require('./router')14 , view = require('./view')15 , toArray = require('./utils').toArray16 , methods = Router.methods.concat('del', 'all')17 , res = require('./response')18 , union = require('./utils').union19 , url = require('url')20 , utils = connect.utils21 , path = require('path')22 , extname = path.extname23 , join = path.join24 , fs = require('fs')25 , qs = require('qs');2627/**28 * Expose `HTTPServer`.29 */3031var app = exports = module.exports = {};3233/**34 * Initialize the server.35 *36 * @param {Array} middleware37 * @api private38 */3940app.init = function(middleware){41 var self = this;42 this.cache = {};43 this.settings = {};44 this.redirects = {};45 this.isCallbacks = {};4647 this.set('home', '/');48 this.set('env', process.env.NODE_ENV || 'development');49 this.use(connect.query());5051 /**52 * Assign several locals with the given `obj`,53 * or return the locals.54 *55 * @param {Object} obj56 * @return {Object|HTTPServer}57 * @api public58 */5960 this.locals = function(obj){61 for (var key in obj) {62 self.locals[key] = obj[key];63 }64 return self;65 };6667 // expose objects to each other68 this.use(function(req, res, next){69 var charset;70 req.query = req.query || {};71 res.setHeader('X-Powered-By', 'Express');72 req.app = res.app = self;73 req.res = res;74 res.req = req;75 req.next = next;7677 // charset78 if (charset = self.set('charset')) res.charset = charset;7980 /**81 * Assign several locals with the given `obj`,82 * or return the locals.83 *84 * @param {Object} obj85 * @return {Object|ServerResponse}86 * @api public87 */8889 res.locals = function(obj){90 for (var key in obj) {91 res.locals[key] = obj[key];92 }93 return res;94 };9596 next();97 });9899 // apply middleware100 if (middleware) middleware.forEach(self.use.bind(self));101102 // router103 this.routes = new Router(this);104 this.__defineGetter__('router', function(){105 this.__usedRouter = true;106 return self.routes.middleware;107 });108109 // default locals110 this.locals.settings = this.settings;111112 // default development configuration113 this.configure('development', function(){114 this.enable('hints');115 });116117 // default production configuration118 this.configure('production', function(){119 this.enable('view cache');120 });121122 // route manipulation methods123 methods.forEach(function(method){124 self.lookup[method] = function(path){125 return self.routes.lookup(method, path);126 };127128 self.match[method] = function(path){129 return self.routes.match(method, path);130 };131132 self.remove[method] = function(path){133 return self.routes.lookup(method, path).remove();134 };135 });136137 // del -> delete138 self.lookup.del = self.lookup.delete;139 self.match.del = self.match.delete;140 self.remove.del = self.remove.delete;141};142143/**144 * Remove routes matching the given `path`.145 *146 * @param {Route} path147 * @return {Boolean}148 * @api public149 */150151app.remove = function(path){152 return this.routes.lookup('all', path).remove();153};154155/**156 * Lookup routes defined with a path157 * equivalent to `path`.158 *159 * @param {Stirng} path160 * @return {Array}161 * @api public162 */163164app.lookup = function(path){165 return this.routes.lookup('all', path);166};167168/**169 * Lookup routes matching the given `url`.170 *171 * @param {Stirng} url172 * @return {Array}173 * @api public174 */175176app.match = function(url){177 return this.routes.match('all', url);178};179180/**181 * Proxy `connect.HTTPServer#use()` to apply settings to182 * mounted applications.183 *184 * @param {String|Function|Server} route185 * @param {Function|Server} middleware186 * @return {Server} for chaining187 * @api public188 */189190app.use = function(route, middleware){191 var app, home, handle;192193 if ('string' != typeof route) {194 middleware = route, route = '/';195 }196197 // express app198 if (middleware.handle && middleware.set) app = middleware;199200 // restore .app property on req and res201 if (app) {202 app.route = route;203 middleware = function(req, res, next) {204 var orig = req.app;205 app.handle(req, res, function(err){206 req.app = res.app = orig;207 next(err);208 });209 };210 }211212 connect.proto.use.call(this, route, middleware);213214 // mounted an app, invoke the hook215 // and adjust some settings216 if (app) {217 base = this.set('basepath') || this.route;218 if ('/' == base) base = '';219 base = base + (app.set('basepath') || app.route);220 app.set('basepath', base);221 app.parent = this;222 if (app.__mounted) app.__mounted.call(app, this);223 }224225 return this;226};227228/**229 * Assign a callback `fn` which is called230 * when this `Server` is passed to `Server#use()`.231 *232 * Examples:233 *234 * var app = express.createServer()235 * , blog = express.createServer();236 *237 * blog.mounted(function(parent){238 * // parent is app239 * // "this" is blog240 * });241 *242 * app.use(blog);243 *244 * @param {Function} fn245 * @return {Server} for chaining246 * @api public247 */248249app.mounted = function(fn){250 this.__mounted = fn;251 return this;252};253254/**255 * See: view.register.256 *257 * @return {Server} for chaining258 * @api public259 */260261app.register = function(){262 view.register.apply(this, arguments);263 return this;264};265266/**267 * Map the given param placeholder `name`(s) to the given callback `fn`.268 * Register the given view helpers `obj`. This method269 * can be called several times to apply additional helpers.270 *271 * @param {Object} obj272 * @return {Server} for chaining273 * @api public274 */275276app.locals = function(obj){277 utils.merge(this._locals, obj);278 return this;279};280281/**282 * Map the given param placeholder `name`(s) to the given callback(s).283 *284 * Param mapping is used to provide pre-conditions to routes285 * which us normalized placeholders. This callback has the same286 * signature as regular middleware, for example below when ":userId"287 * is used this function will be invoked in an attempt to load the user.288 *289 * app.param('userId', function(req, res, next, id){290 * User.find(id, function(err, user){291 * if (err) {292 * next(err);293 * } else if (user) {294 * req.user = user;295 * next();296 * } else {297 * next(new Error('failed to load user'));298 * }299 * });300 * });301 *302 * Passing a single function allows you to map logic303 * to the values passed to `app.param()`, for example304 * this is useful to provide coercion support in a concise manner.305 *306 * The following example maps regular expressions to param values307 * ensuring that they match, otherwise passing control to the next308 * route:309 *310 * app.param(function(name, regexp){311 * if (regexp instanceof RegExp) {312 * return function(req, res, next, val){313 * var captures;314 * if (captures = regexp.exec(String(val))) {315 * req.params[name] = captures;316 * next();317 * } else {318 * next('route');319 * }320 * }321 * }322 * });323 *324 * We can now use it as shown below, where "/commit/:commit" expects325 * that the value for ":commit" is at 5 or more digits. The capture326 * groups are then available as `req.params.commit` as we defined327 * in the function above.328 *329 * app.param('commit', /^\d{5,}$/);330 *331 * For more of this useful functionality take a look332 * at [express-params](http://github.com/visionmedia/express-params).333 *334 * @param {String|Array|Function} name335 * @param {Function} fn336 * @return {Server} for chaining337 * @api public338 */339340app.param = function(name, fn){341 var self = this342 , fns = [].slice.call(arguments, 1);343344 // array345 if (Array.isArray(name)) {346 name.forEach(function(name){347 fns.forEach(function(fn){348 self.param(name, fn);349 });350 });351 // param logic352 } else if ('function' == typeof name) {353 this.routes.param(name);354 // single355 } else {356 if (':' == name[0]) name = name.substr(1);357 fns.forEach(function(fn){358 self.routes.param(name, fn);359 });360 }361362 return this;363};364365/**366 * Register the given callback `fn` for the given `type`.367 *368 * @param {String} type369 * @param {Function} fn370 * @return {Server} for chaining371 * @api public372 */373374app.is = function(type, fn){375 if (!fn) return this.isCallbacks[type];376 this.isCallbacks[type] = fn;377 return this;378};379380/**381 * Assign `setting` to `val`, or return `setting`'s value.382 * Mounted servers inherit their parent server's settings.383 *384 * @param {String} setting385 * @param {String} val386 * @return {Server|Mixed} for chaining, or the setting value387 * @api public388 */389390app.set = function(setting, val){391 if (val === undefined) {392 if (this.settings.hasOwnProperty(setting)) {393 return this.settings[setting];394 } else if (this.parent) {395 return this.parent.set(setting);396 }397 } else {398 this.settings[setting] = val;399 return this;400 }401};402403/**404 * Check if `setting` is enabled.405 *406 * @param {String} setting407 * @return {Boolean}408 * @api public409 */410411app.enabled = function(setting){412 return !!this.set(setting);413};414415/**416 * Check if `setting` is disabled.417 *418 * @param {String} setting419 * @return {Boolean}420 * @api public421 */422423app.disabled = function(setting){424 return !this.set(setting);425};426427/**428 * Enable `setting`.429 *430 * @param {String} setting431 * @return {Server} for chaining432 * @api public433 */434435app.enable = function(setting){436 return this.set(setting, true);437};438439/**440 * Disable `setting`.441 *442 * @param {String} setting443 * @return {Server} for chaining444 * @api public445 */446447app.disable = function(setting){448 return this.set(setting, false);449};450451/**452 * Redirect `key` to `url`.453 *454 * @param {String} key455 * @param {String} url456 * @return {Server} for chaining457 * @api public458 */459460app.redirect = function(key, url){461 this.redirects[key] = url;462 return this;463};464465/**466 * Configure callback for zero or more envs,467 * when no env is specified that callback will468 * be invoked for all environments. Any combination469 * can be used multiple times, in any order desired.470 *471 * Examples:472 *473 * app.configure(function(){474 * // executed for all envs475 * });476 *477 * app.configure('stage', function(){478 * // executed staging env479 * });480 *481 * app.configure('stage', 'production', function(){482 * // executed for stage and production483 * });484 *485 * @param {String} env...486 * @param {Function} fn487 * @return {Server} for chaining488 * @api public489 */490491app.configure = function(env, fn){492 var envs = 'all'493 , args = toArray(arguments);494 fn = args.pop();495 if (args.length) envs = args;496 if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this);497 return this;498};499500/**501 * Delegate `.VERB(...)` calls to `.route(VERB, ...)`.502 */503504methods.forEach(function(method){505 app[method] = function(path){506 if (1 == arguments.length) return this.routes.lookup(method, path);507 var args = [method].concat(toArray(arguments));508 if (!this.__usedRouter) this.use(this.router);509 return this.routes._route.apply(this.routes, args);510 }511});512513/**514 * Special-cased "all" method, applying the given route `path`,515 * middleware, and callback to _every_ HTTP method.516 *517 * @param {String} path518 * @param {Function} ...519 * @return {Server} for chaining520 * @api public521 */522523app.all = function(path){524 var args = arguments;525 if (1 == args.length) return this.routes.lookup('all', path);526 methods.forEach(function(method){527 if ('all' == method) return;528 app[method].apply(this, args);529 }, this);530 return this;531};532533// del -> delete alias534535app.del = app.delete;536537/**538 * Render the given `view` name with `opts`539 * and a callback accepting an error and the540 * rendered template string.541 *542 * @param {String} view543 * @param {String|Function} opts or fn544 * @param {Function} fn545 * @api public546 */547548app.render = function(view, opts, fn){549 var self = this550 , options = {}551 , cache = this.cache552 , engines = this.engines553 , root = this.set('views') || process.cwd() + '/views';554555 // support callback function as second arg556 if ('function' == typeof opts) {557 fn = opts, opts = null;558 }559560 // merge app.locals561 union(options, this.locals);562563 // merge render() options564 if (opts) utils.merge(options, opts);565566 // join "view engine" if necessary567 var ext = extname(view);568 if (!ext) view += '.' + (ext = this.set('view engine'));569570 // pass .cache to the engine571 options.cache = this.enabled('view cache');572573 // when no extension nor "view engine" is given574 if (!ext) return fn(new Error('failed to find view "' + view + '"'));575576 // render577 try {578 var engine = cache[ext] = cache[ext] || require(ext);579 options.filename = join(root, view);580 view = fs.readFileSync(options.filename, 'utf8');581 engine.render(view, options, fn);582 } catch (err) {583 fn(err);584 }585};
modified:lib/express.js+1 added-1 removed
deleted:lib/proto.js-585 removed
12/*!3 * Express - proto4 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>5 * MIT Licensed6 */78/**9 * Module dependencies.10 */1112var connect = require('connect')13 , Router = require('./router')14 , view = require('./view')15 , toArray = require('./utils').toArray16 , methods = Router.methods.concat('del', 'all')17 , res = require('./response')18 , union = require('./utils').union19 , url = require('url')20 , utils = connect.utils21 , path = require('path')22 , extname = path.extname23 , join = path.join24 , fs = require('fs')25 , qs = require('qs');2627/**28 * Expose `HTTPServer`.29 */3031var app = exports = module.exports = {};3233/**34 * Initialize the server.35 *36 * @param {Array} middleware37 * @api private38 */3940app.init = function(middleware){41 var self = this;42 this.cache = {};43 this.settings = {};44 this.redirects = {};45 this.isCallbacks = {};4647 this.set('home', '/');48 this.set('env', process.env.NODE_ENV || 'development');49 this.use(connect.query());5051 /**52 * Assign several locals with the given `obj`,53 * or return the locals.54 *55 * @param {Object} obj56 * @return {Object|HTTPServer}57 * @api public58 */5960 this.locals = function(obj){61 for (var key in obj) {62 self.locals[key] = obj[key];63 }64 return self;65 };6667 // expose objects to each other68 this.use(function(req, res, next){69 var charset;70 req.query = req.query || {};71 res.setHeader('X-Powered-By', 'Express');72 req.app = res.app = self;73 req.res = res;74 res.req = req;75 req.next = next;7677 // charset78 if (charset = self.set('charset')) res.charset = charset;7980 /**81 * Assign several locals with the given `obj`,82 * or return the locals.83 *84 * @param {Object} obj85 * @return {Object|ServerResponse}86 * @api public87 */8889 res.locals = function(obj){90 for (var key in obj) {91 res.locals[key] = obj[key];92 }93 return res;94 };9596 next();97 });9899 // apply middleware100 if (middleware) middleware.forEach(self.use.bind(self));101102 // router103 this.routes = new Router(this);104 this.__defineGetter__('router', function(){105 this.__usedRouter = true;106 return self.routes.middleware;107 });108109 // default locals110 this.locals.settings = this.settings;111112 // default development configuration113 this.configure('development', function(){114 this.enable('hints');115 });116117 // default production configuration118 this.configure('production', function(){119 this.enable('view cache');120 });121122 // route manipulation methods123 methods.forEach(function(method){124 self.lookup[method] = function(path){125 return self.routes.lookup(method, path);126 };127128 self.match[method] = function(path){129 return self.routes.match(method, path);130 };131132 self.remove[method] = function(path){133 return self.routes.lookup(method, path).remove();134 };135 });136137 // del -> delete138 self.lookup.del = self.lookup.delete;139 self.match.del = self.match.delete;140 self.remove.del = self.remove.delete;141};142143/**144 * Remove routes matching the given `path`.145 *146 * @param {Route} path147 * @return {Boolean}148 * @api public149 */150151app.remove = function(path){152 return this.routes.lookup('all', path).remove();153};154155/**156 * Lookup routes defined with a path157 * equivalent to `path`.158 *159 * @param {Stirng} path160 * @return {Array}161 * @api public162 */163164app.lookup = function(path){165 return this.routes.lookup('all', path);166};167168/**169 * Lookup routes matching the given `url`.170 *171 * @param {Stirng} url172 * @return {Array}173 * @api public174 */175176app.match = function(url){177 return this.routes.match('all', url);178};179180/**181 * Proxy `connect.HTTPServer#use()` to apply settings to182 * mounted applications.183 *184 * @param {String|Function|Server} route185 * @param {Function|Server} middleware186 * @return {Server} for chaining187 * @api public188 */189190app.use = function(route, middleware){191 var app, home, handle;192193 if ('string' != typeof route) {194 middleware = route, route = '/';195 }196197 // express app198 if (middleware.handle && middleware.set) app = middleware;199200 // restore .app property on req and res201 if (app) {202 app.route = route;203 middleware = function(req, res, next) {204 var orig = req.app;205 app.handle(req, res, function(err){206 req.app = res.app = orig;207 next(err);208 });209 };210 }211212 connect.proto.use.call(this, route, middleware);213214 // mounted an app, invoke the hook215 // and adjust some settings216 if (app) {217 base = this.set('basepath') || this.route;218 if ('/' == base) base = '';219 base = base + (app.set('basepath') || app.route);220 app.set('basepath', base);221 app.parent = this;222 if (app.__mounted) app.__mounted.call(app, this);223 }224225 return this;226};227228/**229 * Assign a callback `fn` which is called230 * when this `Server` is passed to `Server#use()`.231 *232 * Examples:233 *234 * var app = express.createServer()235 * , blog = express.createServer();236 *237 * blog.mounted(function(parent){238 * // parent is app239 * // "this" is blog240 * });241 *242 * app.use(blog);243 *244 * @param {Function} fn245 * @return {Server} for chaining246 * @api public247 */248249app.mounted = function(fn){250 this.__mounted = fn;251 return this;252};253254/**255 * See: view.register.256 *257 * @return {Server} for chaining258 * @api public259 */260261app.register = function(){262 view.register.apply(this, arguments);263 return this;264};265266/**267 * Map the given param placeholder `name`(s) to the given callback `fn`.268 * Register the given view helpers `obj`. This method269 * can be called several times to apply additional helpers.270 *271 * @param {Object} obj272 * @return {Server} for chaining273 * @api public274 */275276app.locals = function(obj){277 utils.merge(this._locals, obj);278 return this;279};280281/**282 * Map the given param placeholder `name`(s) to the given callback(s).283 *284 * Param mapping is used to provide pre-conditions to routes285 * which us normalized placeholders. This callback has the same286 * signature as regular middleware, for example below when ":userId"287 * is used this function will be invoked in an attempt to load the user.288 *289 * app.param('userId', function(req, res, next, id){290 * User.find(id, function(err, user){291 * if (err) {292 * next(err);293 * } else if (user) {294 * req.user = user;295 * next();296 * } else {297 * next(new Error('failed to load user'));298 * }299 * });300 * });301 *302 * Passing a single function allows you to map logic303 * to the values passed to `app.param()`, for example304 * this is useful to provide coercion support in a concise manner.305 *306 * The following example maps regular expressions to param values307 * ensuring that they match, otherwise passing control to the next308 * route:309 *310 * app.param(function(name, regexp){311 * if (regexp instanceof RegExp) {312 * return function(req, res, next, val){313 * var captures;314 * if (captures = regexp.exec(String(val))) {315 * req.params[name] = captures;316 * next();317 * } else {318 * next('route');319 * }320 * }321 * }322 * });323 *324 * We can now use it as shown below, where "/commit/:commit" expects325 * that the value for ":commit" is at 5 or more digits. The capture326 * groups are then available as `req.params.commit` as we defined327 * in the function above.328 *329 * app.param('commit', /^\d{5,}$/);330 *331 * For more of this useful functionality take a look332 * at [express-params](http://github.com/visionmedia/express-params).333 *334 * @param {String|Array|Function} name335 * @param {Function} fn336 * @return {Server} for chaining337 * @api public338 */339340app.param = function(name, fn){341 var self = this342 , fns = [].slice.call(arguments, 1);343344 // array345 if (Array.isArray(name)) {346 name.forEach(function(name){347 fns.forEach(function(fn){348 self.param(name, fn);349 });350 });351 // param logic352 } else if ('function' == typeof name) {353 this.routes.param(name);354 // single355 } else {356 if (':' == name[0]) name = name.substr(1);357 fns.forEach(function(fn){358 self.routes.param(name, fn);359 });360 }361362 return this;363};364365/**366 * Register the given callback `fn` for the given `type`.367 *368 * @param {String} type369 * @param {Function} fn370 * @return {Server} for chaining371 * @api public372 */373374app.is = function(type, fn){375 if (!fn) return this.isCallbacks[type];376 this.isCallbacks[type] = fn;377 return this;378};379380/**381 * Assign `setting` to `val`, or return `setting`'s value.382 * Mounted servers inherit their parent server's settings.383 *384 * @param {String} setting385 * @param {String} val386 * @return {Server|Mixed} for chaining, or the setting value387 * @api public388 */389390app.set = function(setting, val){391 if (val === undefined) {392 if (this.settings.hasOwnProperty(setting)) {393 return this.settings[setting];394 } else if (this.parent) {395 return this.parent.set(setting);396 }397 } else {398 this.settings[setting] = val;399 return this;400 }401};402403/**404 * Check if `setting` is enabled.405 *406 * @param {String} setting407 * @return {Boolean}408 * @api public409 */410411app.enabled = function(setting){412 return !!this.set(setting);413};414415/**416 * Check if `setting` is disabled.417 *418 * @param {String} setting419 * @return {Boolean}420 * @api public421 */422423app.disabled = function(setting){424 return !this.set(setting);425};426427/**428 * Enable `setting`.429 *430 * @param {String} setting431 * @return {Server} for chaining432 * @api public433 */434435app.enable = function(setting){436 return this.set(setting, true);437};438439/**440 * Disable `setting`.441 *442 * @param {String} setting443 * @return {Server} for chaining444 * @api public445 */446447app.disable = function(setting){448 return this.set(setting, false);449};450451/**452 * Redirect `key` to `url`.453 *454 * @param {String} key455 * @param {String} url456 * @return {Server} for chaining457 * @api public458 */459460app.redirect = function(key, url){461 this.redirects[key] = url;462 return this;463};464465/**466 * Configure callback for zero or more envs,467 * when no env is specified that callback will468 * be invoked for all environments. Any combination469 * can be used multiple times, in any order desired.470 *471 * Examples:472 *473 * app.configure(function(){474 * // executed for all envs475 * });476 *477 * app.configure('stage', function(){478 * // executed staging env479 * });480 *481 * app.configure('stage', 'production', function(){482 * // executed for stage and production483 * });484 *485 * @param {String} env...486 * @param {Function} fn487 * @return {Server} for chaining488 * @api public489 */490491app.configure = function(env, fn){492 var envs = 'all'493 , args = toArray(arguments);494 fn = args.pop();495 if (args.length) envs = args;496 if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this);497 return this;498};499500/**501 * Delegate `.VERB(...)` calls to `.route(VERB, ...)`.502 */503504methods.forEach(function(method){505 app[method] = function(path){506 if (1 == arguments.length) return this.routes.lookup(method, path);507 var args = [method].concat(toArray(arguments));508 if (!this.__usedRouter) this.use(this.router);509 return this.routes._route.apply(this.routes, args);510 }511});512513/**514 * Special-cased "all" method, applying the given route `path`,515 * middleware, and callback to _every_ HTTP method.516 *517 * @param {String} path518 * @param {Function} ...519 * @return {Server} for chaining520 * @api public521 */522523app.all = function(path){524 var args = arguments;525 if (1 == args.length) return this.routes.lookup('all', path);526 methods.forEach(function(method){527 if ('all' == method) return;528 app[method].apply(this, args);529 }, this);530 return this;531};532533// del -> delete alias534535app.del = app.delete;536537/**538 * Render the given `view` name with `opts`539 * and a callback accepting an error and the540 * rendered template string.541 *542 * @param {String} view543 * @param {String|Function} opts or fn544 * @param {Function} fn545 * @api public546 */547548app.render = function(view, opts, fn){549 var self = this550 , options = {}551 , cache = this.cache552 , engines = this.engines553 , root = this.set('views') || process.cwd() + '/views';554555 // support callback function as second arg556 if ('function' == typeof opts) {557 fn = opts, opts = null;558 }559560 // merge app.locals561 union(options, this.locals);562563 // merge render() options564 if (opts) utils.merge(options, opts);565566 // join "view engine" if necessary567 var ext = extname(view);568 if (!ext) view += '.' + (ext = this.set('view engine'));569570 // pass .cache to the engine571 options.cache = this.enabled('view cache');572573 // when no extension nor "view engine" is given574 if (!ext) return fn(new Error('failed to find view "' + view + '"'));575576 // render577 try {578 var engine = cache[ext] = cache[ext] || require(ext);579 options.filename = join(root, view);580 view = fs.readFileSync(options.filename, 'utf8');581 engine.render(view, options, fn);582 } catch (err) {583 fn(err);584 }585};