application.js
This file
Path
lib/application.js
643 lines · 13.9 KiB · JavaScript
Last changed by
Add settings to debug outputDouglas Christopher Wilsonbefore adoption2a45589
History of this fileTake it
The walk stopped after 200 commits: lines older than 94f10c2 point at it.
Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024
lines 1–8why, one step back1/*!2 * express3 * Copyright(c) 2009-2013 TJ Holowaychuk4 * Copyright(c) 2013 Roman Shtylman5 * Copyright(c) 2014-2015 Douglas Christopher Wilson6 * MIT Licensed7 */8perf: enable strict modeDouglas Christopher Wilsonbefore adoptione71014f
lines 9–10why, one step back9'use strict';10Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 11–12why, one step back11/**12 * Module dependencies.perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 13why, one step back13 * @privateFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 14–27why, one step back14 */1516var finalhandler = require('finalhandler');17var Router = require('./router');18var methods = require('methods');19var middleware = require('./middleware/init');20var query = require('./middleware/query');21var debug = require('debug')('express:application');22var View = require('./view');23var http = require('http');24var compileETag = require('./utils').compileETag;25var compileQueryParser = require('./utils').compileQueryParser;26var compileTrust = require('./utils').compileTrust;27var deprecate = require('depd')('express');Use array-flatten module for flattening arraysDeepak Kapoorbefore adoptionf7e94a3
line 28why, one step back28var flatten = require('array-flatten');Merge tag '3.18.1'Douglas Christopher Wilsonbefore adoptionccc45a7
line 29why, one step back29var merge = require('utils-merge');Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 30–39why, one step back30var resolve = require('path').resolve;31var slice = Array.prototype.slice;3233/**34 * Application prototype.35 */3637var app = exports = module.exports = {};3839/**Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024
line 40why, one step back40 * Variable for trust proxy inheritance back-compatperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 41why, one step back41 * @privateMerge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024
lines 42–46why, one step back42 */4344var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';4546/**Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 47–52why, one step back47 * Initialize the server.48 *49 * - setup default configuration50 * - setup default middleware51 * - setup route reflection methods52 *perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 53why, one step back53 * @privateFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 54–55why, one step back54 */55perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 56why, one step back56app.init = function init() {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 57–58why, one step back57 this.cache = {};58 this.engines = {};perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 59–60why, one step back59 this.settings = {};60Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 61–65why, one step back61 this.defaultConfiguration();62};6364/**65 * Initialize application configuration.perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 66why, one step back66 * @privateFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 67–68why, one step back67 */68perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 69–71why, one step back69app.defaultConfiguration = function defaultConfiguration() {70 var env = process.env.NODE_ENV || 'development';71Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 72–79why, one step back72 // default settings73 this.enable('x-powered-by');74 this.set('etag', 'weak');75 this.set('env', env);76 this.set('query parser', 'extended');77 this.set('subdomain offset', 2);78 this.set('trust proxy', false);79Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024
lines 80–85why, one step back80 // trust proxy inherit back-compat81 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {82 configurable: true,83 value: true84 });85Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 86–87why, one step back86 debug('booting in %s mode', env);87Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024
lines 88–96why, one step back88 this.on('mount', function onmount(parent) {89 // inherit trust proxy90 if (this.settings[trustProxyDefaultSymbol] === true91 && typeof parent.settings['trust proxy fn'] === 'function') {92 delete this.settings['trust proxy'];93 delete this.settings['trust proxy fn'];94 }9596 // inherit protosFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 97–133why, one step back97 this.request.__proto__ = parent.request;98 this.response.__proto__ = parent.response;99 this.engines.__proto__ = parent.engines;100 this.settings.__proto__ = parent.settings;101 });102103 // setup locals104 this.locals = Object.create(null);105106 // top-most app is mounted at /107 this.mountpath = '/';108109 // default locals110 this.locals.settings = this.settings;111112 // default configuration113 this.set('view', View);114 this.set('views', resolve('views'));115 this.set('jsonp callback name', 'callback');116117 if (env === 'production') {118 this.enable('view cache');119 }120121 Object.defineProperty(this, 'router', {122 get: function() {123 throw new Error('\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.');124 }125 });126};127128/**129 * lazily adds the base router if it has not yet been added.130 *131 * We cannot add the base router in the defaultConfiguration because132 * it reads app settings which might be set after that has run.133 *perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 134why, one step back134 * @privateFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
line 135why, one step back135 */perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 136why, one step back136app.lazyrouter = function lazyrouter() {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 137–150why, one step back137 if (!this._router) {138 this._router = new Router({139 caseSensitive: this.enabled('case sensitive routing'),140 strict: this.enabled('strict routing')141 });142143 this._router.use(query(this.get('query parser fn')));144 this._router.use(middleware.init(this));145 }146};147148/**149 * Dispatch a req, res pair into the application. Starts pipeline processing.150 *perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 151why, one step back151 * If no callback is provided, then default error handlers will respondFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 152–153why, one step back152 * in the event of an error bubbling through the stack.153 *perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 154why, one step back154 * @privateFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 155–156why, one step back155 */156perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 157why, one step back157app.handle = function handle(req, res, callback) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 158–160why, one step back158 var router = this._router;159160 // final handlerperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 161why, one step back161 var done = callback || finalhandler(req, res, {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 162–182why, one step back162 env: this.get('env'),163 onerror: logerror.bind(this)164 });165166 // no routes167 if (!router) {168 debug('no routes defined on app');169 done();170 return;171 }172173 router.handle(req, res, done);174};175176/**177 * Proxy `Router#use()` to add middleware to the app router.178 * See Router#use() documentation for details.179 *180 * If the _fn_ parameter is an express app, then it will be181 * mounted at the _route_ specified.182 *perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 183why, one step back183 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 184–223why, one step back184 */185186app.use = function use(fn) {187 var offset = 0;188 var path = '/';189190 // default path to '/'191 // disambiguate app.use([fn])192 if (typeof fn !== 'function') {193 var arg = fn;194195 while (Array.isArray(arg) && arg.length !== 0) {196 arg = arg[0];197 }198199 // first arg is the path200 if (typeof arg !== 'function') {201 offset = 1;202 path = fn;203 }204 }205206 var fns = flatten(slice.call(arguments, offset));207208 if (fns.length === 0) {209 throw new TypeError('app.use() requires middleware functions');210 }211212 // setup router213 this.lazyrouter();214 var router = this._router;215216 fns.forEach(function (fn) {217 // non-express app218 if (!fn || !fn.handle || !fn.set) {219 return router.use(path, fn);220 }221222 debug('.use app under %s', path);223 fn.mountpath = path;Pass context to .forEach instead of closurelemmybefore adoptiondfa7ee4
line 224why, one step back224 fn.parent = this;Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 225–236why, one step back225226 // restore .app property on req and res227 router.use(path, function mounted_app(req, res, next) {228 var orig = req.app;229 fn.handle(req, res, function (err) {230 req.__proto__ = orig.request;231 res.__proto__ = orig.response;232 next(err);233 });234 });235236 // mounted an appPass context to .forEach instead of closurelemmybefore adoptiondfa7ee4
lines 237–238why, one step back237 fn.emit('mount', this);238 }, this);Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 239–249why, one step back239240 return this;241};242243/**244 * Proxy to the app `Router#route()`245 * Returns a new `Route` instance for the _path_.246 *247 * Routes are isolated middleware stacks for specific paths.248 * See the Route api docs for details.249 *perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 250why, one step back250 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 251–252why, one step back251 */252perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 253why, one step back253app.route = function route(path) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 254–280why, one step back254 this.lazyrouter();255 return this._router.route(path);256};257258/**259 * Register the given template engine callback `fn`260 * as `ext`.261 *262 * By default will `require()` the engine based on the263 * file extension. For example if you try to render264 * a "foo.jade" file Express will invoke the following internally:265 *266 * app.engine('jade', require('jade').__express);267 *268 * For engines that do not provide `.__express` out of the box,269 * or if you wish to "map" a different extension to the template engine270 * you may use this method. For example mapping the EJS template engine to271 * ".html" files:272 *273 * app.engine('html', require('ejs').renderFile);274 *275 * In this case EJS provides a `.renderFile()` method with276 * the same signature that Express expects: `(path, options, callback)`,277 * though note that it aliases this method as `ejs.__express` internally278 * so if you're using ".ejs" extensions you dont need to do anything.279 *280 * Some template engines do not follow this convention, thedocs: visionmedia is now tj on GithubDouglas Christopher Wilsonbefore adoptione9539fc
line 281why, one step back281 * [Consolidate.js](https://github.com/tj/consolidate.js)Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 282–288why, one step back282 * library was created to map all of node's popular template283 * engines to follow this convention, thus allowing them to284 * work seamlessly within Express.285 *286 * @param {String} ext287 * @param {Function} fn288 * @return {app} for chainingperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 289why, one step back289 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 290–291why, one step back290 */291perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 292–304why, one step back292app.engine = function engine(ext, fn) {293 if (typeof fn !== 'function') {294 throw new Error('callback function required');295 }296297 // get file extension298 var extension = ext[0] !== '.'299 ? '.' + ext300 : ext;301302 // store engine303 this.engines[extension] = fn;304Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 305–316why, one step back305 return this;306};307308/**309 * Proxy to `Router#param()` with one added api feature. The _name_ parameter310 * can be an array of names.311 *312 * See the Router#param() docs for more details.313 *314 * @param {String|Array} name315 * @param {Function} fn316 * @return {app} for chainingperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 317why, one step back317 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 318–319why, one step back318 */319perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 320why, one step back320app.param = function param(name, fn) {Pass context to .forEach instead of closurelemmybefore adoptiondfa7ee4
line 321why, one step back321 this.lazyrouter();Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 322–323why, one step back322323 if (Array.isArray(name)) {perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 324–327why, one step back324 for (var i = 0; i < name.length; i++) {325 this.param(name[i], fn);326 }327Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 328–330why, one step back328 return this;329 }330Pass context to .forEach instead of closurelemmybefore adoptiondfa7ee4
line 331why, one step back331 this._router.param(name, fn);perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 332why, one step back332Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 333–347why, one step back333 return this;334};335336/**337 * Assign `setting` to `val`, or return `setting`'s value.338 *339 * app.set('foo', 'bar');340 * app.get('foo');341 * // => "bar"342 *343 * Mounted servers inherit their parent server's settings.344 *345 * @param {String} setting346 * @param {*} [val]347 * @return {Server} for chainingperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 348why, one step back348 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 349–350why, one step back349 */350perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 351why, one step back351app.set = function set(setting, val) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 352–356why, one step back352 if (arguments.length === 1) {353 // app.get(setting)354 return this.settings[setting];355 }356Add settings to debug outputDouglas Christopher Wilsonbefore adoption2a45589
lines 357–358why, one step back357 debug('set "%s" to %o', setting, val);358Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 359–371why, one step back359 // set value360 this.settings[setting] = val;361362 // trigger matched settings363 switch (setting) {364 case 'etag':365 this.set('etag fn', compileETag(val));366 break;367 case 'query parser':368 this.set('query parser fn', compileQueryParser(val));369 break;370 case 'trust proxy':371 this.set('trust proxy fn', compileTrust(val));Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024
lines 372–378why, one step back372373 // trust proxy inherit back-compat374 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {375 configurable: true,376 value: false377 });378Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 379–395why, one step back379 break;380 }381382 return this;383};384385/**386 * Return the app's absolute pathname387 * based on the parent(s) that have388 * mounted it.389 *390 * For example if the application was391 * mounted as "/admin", which itself392 * was mounted as "/blog" then the393 * return value would be "/blog/admin".394 *395 * @return {String}perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 396why, one step back396 * @privateFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 397–398why, one step back397 */398perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 399why, one step back399app.path = function path() {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 400–416why, one step back400 return this.parent401 ? this.parent.path() + this.mountpath402 : '';403};404405/**406 * Check if `setting` is enabled (truthy).407 *408 * app.enabled('foo')409 * // => false410 *411 * app.enable('foo')412 * app.enabled('foo')413 * // => true414 *415 * @param {String} setting416 * @return {Boolean}perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 417why, one step back417 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 418–419why, one step back418 */419perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 420–421why, one step back420app.enabled = function enabled(setting) {421 return Boolean(this.set(setting));Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 422–435why, one step back422};423424/**425 * Check if `setting` is disabled.426 *427 * app.disabled('foo')428 * // => true429 *430 * app.enable('foo')431 * app.disabled('foo')432 * // => false433 *434 * @param {String} setting435 * @return {Boolean}perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 436why, one step back436 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 437–438why, one step back437 */438perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 439why, one step back439app.disabled = function disabled(setting) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 440–447why, one step back440 return !this.set(setting);441};442443/**444 * Enable `setting`.445 *446 * @param {String} setting447 * @return {app} for chainingperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 448why, one step back448 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 449–450why, one step back449 */450perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 451why, one step back451app.enable = function enable(setting) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 452–459why, one step back452 return this.set(setting, true);453};454455/**456 * Disable `setting`.457 *458 * @param {String} setting459 * @return {app} for chainingperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 460why, one step back460 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 461–462why, one step back461 */462perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 463why, one step back463app.disable = function disable(setting) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 464–472why, one step back464 return this.set(setting, false);465};466467/**468 * Delegate `.VERB(...)` calls to `router.VERB(...)`.469 */470471methods.forEach(function(method){472 app[method] = function(path){perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 473–476why, one step back473 if (method === 'get' && arguments.length === 1) {474 // app.get(setting)475 return this.set(path);476 }Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 477–492why, one step back477478 this.lazyrouter();479480 var route = this._router.route(path);481 route[method].apply(route, slice.call(arguments, 1));482 return this;483 };484});485486/**487 * Special-cased "all" method, applying the given route `path`,488 * middleware, and callback to _every_ HTTP method.489 *490 * @param {String} path491 * @param {Function} ...492 * @return {app} for chainingperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 493why, one step back493 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 494–495why, one step back494 */495perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 496why, one step back496app.all = function all(path) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 497–501why, one step back497 this.lazyrouter();498499 var route = this._router.route(path);500 var args = slice.call(arguments, 1);501perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 502–505why, one step back502 for (var i = 0; i < methods.length; i++) {503 route[methods[i]].apply(route, args);504 }505Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 506–525why, one step back506 return this;507};508509// del -> delete alias510511app.del = deprecate.function(app.delete, 'app.del: Use app.delete instead');512513/**514 * Render the given view `name` name with `options`515 * and a callback accepting an error and the516 * rendered template string.517 *518 * Example:519 *520 * app.render('email', { name: 'Tobi' }, function(err, html){521 * // ...522 * })523 *524 * @param {String} name525 * @param {String|Function} options or fnperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 526–527why, one step back526 * @param {Function} callback527 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 528–529why, one step back528 */529perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 530why, one step back530app.render = function render(name, options, callback) {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
line 531why, one step back531 var cache = this.cache;perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 532why, one step back532 var done = callback;Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
line 533why, one step back533 var engines = this.engines;perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 534–535why, one step back534 var opts = options;535 var renderOptions = {};Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 536–538why, one step back536 var view;537538 // support callback function as second argperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 539–541why, one step back539 if (typeof options === 'function') {540 done = options;541 opts = {};Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 542–544why, one step back542 }543544 // merge app.localsperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 545why, one step back545 merge(renderOptions, this.locals);Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 546–547why, one step back546547 // merge options._localsperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 548–549why, one step back548 if (opts._locals) {549 merge(renderOptions, opts._locals);Merge tag '3.18.1'Douglas Christopher Wilsonbefore adoptionccc45a7
line 550why, one step back550 }Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 551–552why, one step back551552 // merge optionsperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 553why, one step back553 merge(renderOptions, opts);Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 554–555why, one step back554555 // set .cache unless explicitly providedperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 556–558why, one step back556 if (renderOptions.cache == null) {557 renderOptions.cache = this.enabled('view cache');558 }Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 559–560why, one step back559560 // primed cacheperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 561–563why, one step back561 if (renderOptions.cache) {562 view = cache[name];563 }Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 564–566why, one step back564565 // view566 if (!view) {perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 567–569why, one step back567 var View = this.get('view');568569 view = new View(name, {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 570–575why, one step back570 defaultEngine: this.get('view engine'),571 root: this.get('views'),572 engines: engines573 });574575 if (!view.path) {Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 576–579why, one step back576 var dirs = Array.isArray(view.root) && view.root.length > 1577 ? 'directories "' + view.root.slice(0, -1).join('", "') + '" or "' + view.root[view.root.length - 1] + '"'578 : 'directory "' + view.root + '"'579 var err = new Error('Failed to lookup view "' + name + '" in views ' + dirs);Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
line 580why, one step back580 err.view = view;perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 581why, one step back581 return done(err);Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 582–584why, one step back582 }583584 // prime the cacheperf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 585–587why, one step back585 if (renderOptions.cache) {586 cache[name] = view;587 }Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 588–590why, one step back588 }589590 // renderperf: isolate app.render try blockDouglas Christopher Wilsonbefore adoptionf5a2406
line 591why, one step back591 tryRender(view, renderOptions, done);Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 592–611why, one step back592};593594/**595 * Listen for connections.596 *597 * A node `http.Server` is returned, with this598 * application (which is a `Function`) as its599 * callback. If you wish to create both an HTTP600 * and HTTPS server you may do so with the "http"601 * and "https" modules as shown here:602 *603 * var http = require('http')604 * , https = require('https')605 * , express = require('express')606 * , app = express();607 *608 * http.createServer(app).listen(80);609 * https.createServer({ ... }, app).listen(443);610 *611 * @return {http.Server}perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 612why, one step back612 * @publicFix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 613–614why, one step back613 */614perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
line 615why, one step back615app.listen = function listen() {Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
lines 616–620why, one step back616 var server = http.createServer(this);617 return server.listen.apply(server, arguments);618};619620/**perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 621–625why, one step back621 * Log error using console.error.622 *623 * @param {Error} err624 * @private625 */Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
line 626why, one step back626perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248
lines 627–628why, one step back627function logerror(err) {628 /* istanbul ignore next */Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
line 629why, one step back629 if (this.get('env') !== 'test') console.error(err.stack || err.toString());perf: isolate app.render try blockDouglas Christopher Wilsonbefore adoptionf5a2406
lines 630–642why, one step back630}631632/**633 * Try rendering a view.634 * @private635 */636637function tryRender(view, options, callback) {638 try {639 view.render(options, callback);640 } catch (err) {641 callback(err);642 }Fix using same param name in array of pathsDouglas Christopher Wilsonbefore adoption94f10c2
line 643why, one step back643}