Skip to content
Myr

application.js

This file

Path

lib/application.js

644 lines · 14.0 KiB · JavaScript

Last changed by

perf: isolate app.render try blockDouglas Christopher Wilsonbefore adoptionf5a2406

History of this file

Take it

The walk stopped after 200 commits: lines older than 6bc7574 point at it.

Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024

lines 1–8why, one step back
1/*!
2 * express3 * Copyright(c) 2009-2013 TJ Holowaychuk4 * Copyright(c) 2013 Roman Shtylman5 * Copyright(c) 2014-2015 Douglas Christopher Wilson6 * MIT Licensed7 */8

perf: enable strict modeDouglas Christopher Wilsonbefore adoptione71014f

lines 9–10why, one step back
9'use strict';
10

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 11–12why, one step back
11/**
12 * Module dependencies.

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 13why, one step back
13 * @private

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 14–27why, one step back
14 */
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 back
28var flatten = require('array-flatten');

Merge tag '3.18.1'Douglas Christopher Wilsonbefore adoptionccc45a7

line 29why, one step back
29var merge = require('utils-merge');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 30–39why, one step back
30var 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 back
40 * Variable for trust proxy inheritance back-compat

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 41why, one step back
41 * @private

Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024

lines 42–46why, one step back
42 */
4344var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';4546/**

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 47–52why, one step back
47 * 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 back
53 * @private

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 54–55why, one step back
54 */
55

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 56why, one step back
56app.init = function init() {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 57–58why, one step back
57 this.cache = {};
58 this.engines = {};

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 59–60why, one step back
59 this.settings = {};
60

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 61–65why, one step back
61 this.defaultConfiguration();
62};6364/**65 * Initialize application configuration.

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 66why, one step back
66 * @private

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 67–68why, one step back
67 */
68

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 69–71why, one step back
69app.defaultConfiguration = function defaultConfiguration() {
70 var env = process.env.NODE_ENV || 'development';71

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 72–79why, one step back
72 // default settings
73 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);79

Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024

lines 80–85why, one step back
80 // trust proxy inherit back-compat
81 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {82 configurable: true,83 value: true84 });85

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 86–87why, one step back
86 debug('booting in %s mode', env);
87

Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024

lines 88–96why, one step back
88 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 protos

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 97–133why, one step back
97 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 back
134 * @private

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 135why, one step back
135 */

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 136why, one step back
136app.lazyrouter = function lazyrouter() {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 137–150why, one step back
137 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 back
151 * If no callback is provided, then default error handlers will respond

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 152–153why, one step back
152 * in the event of an error bubbling through the stack.
153 *

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 154why, one step back
154 * @private

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 155–156why, one step back
155 */
156

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 157why, one step back
157app.handle = function handle(req, res, callback) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 158–160why, one step back
158 var router = this._router;
159160 // final handler

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 161why, one step back
161 var done = callback || finalhandler(req, res, {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 162–182why, one step back
162 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 back
183 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 184–190why, one step back
184 */
185186app.use = function use(fn) {187 var offset = 0;188 var path = '/';189190 // default path to '/'

Fix app.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoptioncf41a8f

line 191why, one step back
191 // disambiguate app.use([fn])

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 192why, one step back
192 if (typeof fn !== 'function') {

Fix app.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoptioncf41a8f

lines 193–198why, one step back
193 var arg = fn;
194195 while (Array.isArray(arg) && arg.length !== 0) {196 arg = arg[0];197 }198

Fix regression for empty string path in app.useDouglas Christopher Wilsonbefore adoption3c1a964

lines 199–200why, one step back
199 // first arg is the path
200 if (typeof arg !== 'function') {

Fix app.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoptioncf41a8f

lines 201–203why, one step back
201 offset = 1;
202 path = fn;203 }

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 204–223why, one step back
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 back
224 fn.parent = this;

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 225–236why, one step back
225
226 // 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 app

Pass context to .forEach instead of closurelemmybefore adoptiondfa7ee4

lines 237–238why, one step back
237 fn.emit('mount', this);
238 }, this);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 239–249why, one step back
239
240 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 back
250 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 251–252why, one step back
251 */
252

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 253why, one step back
253app.route = function route(path) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 254–280why, one step back
254 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, the

docs: visionmedia is now tj on GithubDouglas Christopher Wilsonbefore adoptione9539fc

line 281why, one step back
281 * [Consolidate.js](https://github.com/tj/consolidate.js)

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 282–288why, one step back
282 * library was created to map all of node's popular template
283 * engines to follow this convention, thus allowing them to284 * work seamlessly within Express.285 *286 * @param {String} ext287 * @param {Function} fn288 * @return {app} for chaining

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 289why, one step back
289 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 290–291why, one step back
290 */
291

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 292–304why, one step back
292app.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;304

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 305–316why, one step back
305 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 chaining

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 317why, one step back
317 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 318–319why, one step back
318 */
319

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 320why, one step back
320app.param = function param(name, fn) {

Pass context to .forEach instead of closurelemmybefore adoptiondfa7ee4

line 321why, one step back
321 this.lazyrouter();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 322–323why, one step back
322
323 if (Array.isArray(name)) {

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 324–327why, one step back
324 for (var i = 0; i < name.length; i++) {
325 this.param(name[i], fn);326 }327

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 328–330why, one step back
328 return this;
329 }330

Pass context to .forEach instead of closurelemmybefore adoptiondfa7ee4

line 331why, one step back
331 this._router.param(name, fn);

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 332why, one step back
332

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 333–347why, one step back
333 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 chaining

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 348why, one step back
348 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 349–350why, one step back
349 */
350

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 351why, one step back
351app.set = function set(setting, val) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 352–372why, one step back
352 if (arguments.length === 1) {
353 // app.get(setting)354 return this.settings[setting];355 }356357 // set value358 this.settings[setting] = val;359360 // trigger matched settings361 switch (setting) {362 case 'etag':363 debug('compile etag %s', val);364 this.set('etag fn', compileETag(val));365 break;366 case 'query parser':367 debug('compile query parser %s', val);368 this.set('query parser fn', compileQueryParser(val));369 break;370 case 'trust proxy':371 debug('compile trust proxy %s', val);372 this.set('trust proxy fn', compileTrust(val));

Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024

lines 373–379why, one step back
373
374 // trust proxy inherit back-compat375 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {376 configurable: true,377 value: false378 });379

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 380–396why, one step back
380 break;
381 }382383 return this;384};385386/**387 * Return the app's absolute pathname388 * based on the parent(s) that have389 * mounted it.390 *391 * For example if the application was392 * mounted as "/admin", which itself393 * was mounted as "/blog" then the394 * return value would be "/blog/admin".395 *396 * @return {String}

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 397why, one step back
397 * @private

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 398–399why, one step back
398 */
399

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 400why, one step back
400app.path = function path() {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 401–417why, one step back
401 return this.parent
402 ? this.parent.path() + this.mountpath403 : '';404};405406/**407 * Check if `setting` is enabled (truthy).408 *409 * app.enabled('foo')410 * // => false411 *412 * app.enable('foo')413 * app.enabled('foo')414 * // => true415 *416 * @param {String} setting417 * @return {Boolean}

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 418why, one step back
418 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 419–420why, one step back
419 */
420

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 421–422why, one step back
421app.enabled = function enabled(setting) {
422 return Boolean(this.set(setting));

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 423–436why, one step back
423};
424425/**426 * Check if `setting` is disabled.427 *428 * app.disabled('foo')429 * // => true430 *431 * app.enable('foo')432 * app.disabled('foo')433 * // => false434 *435 * @param {String} setting436 * @return {Boolean}

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 437why, one step back
437 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 438–439why, one step back
438 */
439

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 440why, one step back
440app.disabled = function disabled(setting) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 441–448why, one step back
441 return !this.set(setting);
442};443444/**445 * Enable `setting`.446 *447 * @param {String} setting448 * @return {app} for chaining

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 449why, one step back
449 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 450–451why, one step back
450 */
451

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 452why, one step back
452app.enable = function enable(setting) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 453–460why, one step back
453 return this.set(setting, true);
454};455456/**457 * Disable `setting`.458 *459 * @param {String} setting460 * @return {app} for chaining

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 461why, one step back
461 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 462–463why, one step back
462 */
463

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 464why, one step back
464app.disable = function disable(setting) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 465–473why, one step back
465 return this.set(setting, false);
466};467468/**469 * Delegate `.VERB(...)` calls to `router.VERB(...)`.470 */471472methods.forEach(function(method){473 app[method] = function(path){

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 474–477why, one step back
474 if (method === 'get' && arguments.length === 1) {
475 // app.get(setting)476 return this.set(path);477 }

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 478–493why, one step back
478
479 this.lazyrouter();480481 var route = this._router.route(path);482 route[method].apply(route, slice.call(arguments, 1));483 return this;484 };485});486487/**488 * Special-cased "all" method, applying the given route `path`,489 * middleware, and callback to _every_ HTTP method.490 *491 * @param {String} path492 * @param {Function} ...493 * @return {app} for chaining

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 494why, one step back
494 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 495–496why, one step back
495 */
496

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 497why, one step back
497app.all = function all(path) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 498–502why, one step back
498 this.lazyrouter();
499500 var route = this._router.route(path);501 var args = slice.call(arguments, 1);502

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 503–506why, one step back
503 for (var i = 0; i < methods.length; i++) {
504 route[methods[i]].apply(route, args);505 }506

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 507–526why, one step back
507 return this;
508};509510// del -> delete alias511512app.del = deprecate.function(app.delete, 'app.del: Use app.delete instead');513514/**515 * Render the given view `name` name with `options`516 * and a callback accepting an error and the517 * rendered template string.518 *519 * Example:520 *521 * app.render('email', { name: 'Tobi' }, function(err, html){522 * // ...523 * })524 *525 * @param {String} name526 * @param {String|Function} options or fn

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 527–528why, one step back
527 * @param {Function} callback
528 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 529–530why, one step back
529 */
530

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 531why, one step back
531app.render = function render(name, options, callback) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 532why, one step back
532 var cache = this.cache;

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 533why, one step back
533 var done = callback;

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 534why, one step back
534 var engines = this.engines;

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 535–536why, one step back
535 var opts = options;
536 var renderOptions = {};

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 537–539why, one step back
537 var view;
538539 // support callback function as second arg

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 540–542why, one step back
540 if (typeof options === 'function') {
541 done = options;542 opts = {};

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 543–545why, one step back
543 }
544545 // merge app.locals

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 546why, one step back
546 merge(renderOptions, this.locals);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 547–548why, one step back
547
548 // merge options._locals

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 549–550why, one step back
549 if (opts._locals) {
550 merge(renderOptions, opts._locals);

Merge tag '3.18.1'Douglas Christopher Wilsonbefore adoptionccc45a7

line 551why, one step back
551 }

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 552–553why, one step back
552
553 // merge options

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 554why, one step back
554 merge(renderOptions, opts);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 555–556why, one step back
555
556 // set .cache unless explicitly provided

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 557–559why, one step back
557 if (renderOptions.cache == null) {
558 renderOptions.cache = this.enabled('view cache');559 }

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 560–561why, one step back
560
561 // primed cache

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 562–564why, one step back
562 if (renderOptions.cache) {
563 view = cache[name];564 }

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 565–567why, one step back
565
566 // view567 if (!view) {

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 568–570why, one step back
568 var View = this.get('view');
569570 view = new View(name, {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 571–576why, one step back
571 defaultEngine: this.get('view engine'),
572 root: this.get('views'),573 engines: engines574 });575576 if (!view.path) {

Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352

lines 577–580why, one step back
577 var dirs = Array.isArray(view.root) && view.root.length > 1
578 ? 'directories "' + view.root.slice(0, -1).join('", "') + '" or "' + view.root[view.root.length - 1] + '"'579 : 'directory "' + view.root + '"'580 var err = new Error('Failed to lookup view "' + name + '" in views ' + dirs);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 581why, one step back
581 err.view = view;

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 582why, one step back
582 return done(err);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 583–585why, one step back
583 }
584585 // prime the cache

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 586–588why, one step back
586 if (renderOptions.cache) {
587 cache[name] = view;588 }

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 589–591why, one step back
589 }
590591 // render

perf: isolate app.render try blockDouglas Christopher Wilsonbefore adoptionf5a2406

line 592why, one step back
592 tryRender(view, renderOptions, done);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 593–612why, one step back
593};
594595/**596 * Listen for connections.597 *598 * A node `http.Server` is returned, with this599 * application (which is a `Function`) as its600 * callback. If you wish to create both an HTTP601 * and HTTPS server you may do so with the "http"602 * and "https" modules as shown here:603 *604 * var http = require('http')605 * , https = require('https')606 * , express = require('express')607 * , app = express();608 *609 * http.createServer(app).listen(80);610 * https.createServer({ ... }, app).listen(443);611 *612 * @return {http.Server}

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 613why, one step back
613 * @public

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 614–615why, one step back
614 */
615

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

line 616why, one step back
616app.listen = function listen() {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 617–621why, one step back
617 var server = http.createServer(this);
618 return server.listen.apply(server, arguments);619};620621/**

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 622–626why, one step back
622 * Log error using console.error.
623 *624 * @param {Error} err625 * @private626 */

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 627why, one step back
627

perf: remove argument reassignments in applicationDouglas Christopher Wilsonbefore adoption1050248

lines 628–629why, one step back
628function logerror(err) {
629 /* istanbul ignore next */

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 630why, one step back
630 if (this.get('env') !== 'test') console.error(err.stack || err.toString());

perf: isolate app.render try blockDouglas Christopher Wilsonbefore adoptionf5a2406

lines 631–643why, one step back
631}
632633/**634 * Try rendering a view.635 * @private636 */637638function tryRender(view, options, callback) {639 try {640 view.render(options, callback);641 } catch (err) {642 callback(err);643 }

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 644why, one step back
644}