application.js
This file
Path
lib/application.js
631 lines · 13.7 KiB · JavaScript
Last changed by
fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
History of this fileTake it
The walk stopped after 200 commits: lines older than 2a0c35a point at it.
Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710
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 */8Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 9–10why, one step back9'use strict';10Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 11–12why, one step back11/**12 * Module dependencies.Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 13why, one step back13 * @privateInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 14–18why, one step back14 */1516var finalhandler = require('finalhandler');17var debug = require('debug')('express:application');18var View = require('./view');fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 19why, one step back19var http = require('node:http');chore: replace `methods` dependency with standard library (#6196)Jon Koopsbefore adoptionb11122b
line 20why, one step back20var methods = require('./utils').methods;Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 21–23why, one step back21var compileETag = require('./utils').compileETag;22var compileQueryParser = require('./utils').compileQueryParser;23var compileTrust = require('./utils').compileTrust;fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 24why, one step back24var resolve = require('node:path').resolve;call callback once on listen errorWesbefore adoptionee40a88
line 25why, one step back25var once = require('once')Use router module for routingDouglas Christopher Wilsonbefore adoptioncec5780
line 26why, one step back26var Router = require('router');Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
lines 27–32why, one step back2728/**29 * Module variables.30 * @private31 */32Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 33why, one step back33var slice = Array.prototype.slice;Merge branch '5.0' into 5-mergectcpipbefore adoptiondde1f7d
line 34why, one step back34var flatten = Array.prototype.flat;Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 35–42why, one step back3536/**37 * Application prototype.38 */3940var app = exports = module.exports = {};4142/**Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710
line 43why, one step back43 * Variable for trust proxy inheritance back-compatMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 44why, one step back44 * @privateMerge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710
lines 45–49why, one step back45 */4647var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';4849/**Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 50–55why, one step back50 * Initialize the server.51 *52 * - setup default configuration53 * - setup default middleware54 * - setup route reflection methods55 *Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 56why, one step back56 * @privateInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 57–58why, one step back57 */58Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 59why, one step back59app.init = function init() {Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
lines 60–61why, one step back60 var router = null;61Use object with null prototype for various app propertiesEvan Hahnbefore adoption1443973
lines 62–64why, one step back62 this.cache = Object.create(null);63 this.engines = Object.create(null);64 this.settings = Object.create(null);Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 65why, one step back65Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 66why, one step back66 this.defaultConfiguration();Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
lines 67–82why, one step back6768 // Setup getting to lazily add base router69 Object.defineProperty(this, 'router', {70 configurable: true,71 enumerable: true,72 get: function getrouter() {73 if (router === null) {74 router = new Router({75 caseSensitive: this.enabled('case sensitive routing'),76 strict: this.enabled('strict routing')77 });78 }7980 return router;81 }82 });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 83–86why, one step back83};8485/**86 * Initialize application configuration.Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 87why, one step back87 * @privateInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 88–89why, one step back88 */89Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 90–92why, one step back90app.defaultConfiguration = function defaultConfiguration() {91 var env = process.env.NODE_ENV || 'development';92Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 93–96why, one step back93 // default settings94 this.enable('x-powered-by');95 this.set('etag', 'weak');96 this.set('env', env);Change query parser setting default to 'simple'Czarekbefore adoption450c468
line 97why, one step back97 this.set('query parser', 'simple')Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 98–100why, one step back98 this.set('subdomain offset', 2);99 this.set('trust proxy', false);100Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710
lines 101–106why, one step back101 // trust proxy inherit back-compat102 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {103 configurable: true,104 value: true105 });106Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 107–108why, one step back107 debug('booting in %s mode', env);108Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710
lines 109–117why, one step back109 this.on('mount', function onmount(parent) {110 // inherit trust proxy111 if (this.settings[trustProxyDefaultSymbol] === true112 && typeof parent.settings['trust proxy fn'] === 'function') {113 delete this.settings['trust proxy'];114 delete this.settings['trust proxy fn'];115 }116117 // inherit protosrefactor: Remove Object.setPrototypeOf polyfill (#6081)Phillip Bartabefore adoption8cb53ea
lines 118–121why, one step back118 Object.setPrototypeOf(this.request, parent.request)119 Object.setPrototypeOf(this.response, parent.response)120 Object.setPrototypeOf(this.engines, parent.engines)121 Object.setPrototypeOf(this.settings, parent.settings)Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 122–145why, one step back122 });123124 // setup locals125 this.locals = Object.create(null);126127 // top-most app is mounted at /128 this.mountpath = '/';129130 // default locals131 this.locals.settings = this.settings;132133 // default configuration134 this.set('view', View);135 this.set('views', resolve('views'));136 this.set('jsonp callback name', 'callback');137138 if (env === 'production') {139 this.enable('view cache');140 }141};142143/**144 * Dispatch a req, res pair into the application. Starts pipeline processing.145 *Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 146why, one step back146 * If no callback is provided, then default error handlers will respondInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 147–148why, one step back147 * in the event of an error bubbling through the stack.148 *Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 149why, one step back149 * @privateInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 150–151why, one step back150 */151Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 152why, one step back152app.handle = function handle(req, res, callback) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 153why, one step back153 // final handlerMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 154why, one step back154 var done = callback || finalhandler(req, res, {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 155–158why, one step back155 env: this.get('env'),156 onerror: logerror.bind(this)157 });158Refactor away init middlewareDouglas Christopher Wilsonbefore adoption78e5054
lines 159–168why, one step back159 // set powered by header160 if (this.enabled('x-powered-by')) {161 res.setHeader('X-Powered-By', 'Express');162 }163164 // set circular references165 req.res = res;166 res.req = req;167168 // alter the prototypesrefactor: Remove Object.setPrototypeOf polyfill (#6081)Phillip Bartabefore adoption8cb53ea
lines 169–170why, one step back169 Object.setPrototypeOf(req, this.request)170 Object.setPrototypeOf(res, this.response)Refactor away init middlewareDouglas Christopher Wilsonbefore adoption78e5054
lines 171–174why, one step back171172 // setup locals173 if (!res.locals) {174 res.locals = Object.create(null);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 175–176why, one step back175 }176Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
line 177why, one step back177 this.router.handle(req, res, done);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 178–186why, one step back178};179180/**181 * Proxy `Router#use()` to add middleware to the app router.182 * See Router#use() documentation for details.183 *184 * If the _fn_ parameter is an express app, then it will be185 * mounted at the _route_ specified.186 *Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 187why, one step back187 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 188–194why, one step back188 */189190app.use = function use(fn) {191 var offset = 0;192 var path = '/';193194 // default path to '/'Fix app.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoptioncf41a8f
line 195why, one step back195 // disambiguate app.use([fn])Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 196why, one step back196 if (typeof fn !== 'function') {Fix app.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoptioncf41a8f
lines 197–202why, one step back197 var arg = fn;198199 while (Array.isArray(arg) && arg.length !== 0) {200 arg = arg[0];201 }202Fix regression for empty string path in app.useDouglas Christopher Wilsonbefore adoption3c1a964
lines 203–204why, one step back203 // first arg is the path204 if (typeof arg !== 'function') {Fix app.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoptioncf41a8f
lines 205–207why, one step back205 offset = 1;206 path = fn;207 }Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 208–209why, one step back208 }209Merge branch '5.0' into 5-mergectcpipbefore adoptiondde1f7d
line 210why, one step back210 var fns = flatten.call(slice.call(arguments, offset), Infinity);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 211–212why, one step back211212 if (fns.length === 0) {Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe
line 213why, one step back213 throw new TypeError('app.use() requires a middleware function')Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 214–215why, one step back214 }215Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
lines 216–217why, one step back216 // get router217 var router = this.router;Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 218–226why, one step back218219 fns.forEach(function (fn) {220 // non-express app221 if (!fn || !fn.handle || !fn.set) {222 return router.use(path, fn);223 }224225 debug('.use app under %s', path);226 fn.mountpath = path;Pass context to .forEach instead of closurelemmybefore adoptiondfa7ee4
line 227why, one step back227 fn.parent = this;Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 228–232why, one step back228229 // restore .app property on req and res230 router.use(path, function mounted_app(req, res, next) {231 var orig = req.app;232 fn.handle(req, res, function (err) {refactor: Remove Object.setPrototypeOf polyfill (#6081)Phillip Bartabefore adoption8cb53ea
lines 233–234why, one step back233 Object.setPrototypeOf(req, orig.request)234 Object.setPrototypeOf(res, orig.response)Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 235–239why, one step back235 next(err);236 });237 });238239 // mounted an appPass context to .forEach instead of closurelemmybefore adoptiondfa7ee4
lines 240–241why, one step back240 fn.emit('mount', this);241 }, this);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 242–252why, one step back242243 return this;244};245246/**247 * Proxy to the app `Router#route()`248 * Returns a new `Route` instance for the _path_.249 *250 * Routes are isolated middleware stacks for specific paths.251 * See the Route api docs for details.252 *Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 253why, one step back253 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 254–255why, one step back254 */255Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
lines 256–257why, one step back256app.route = function route(path) {257 return this.router.route(path);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 258–265why, one step back258};259260/**261 * Register the given template engine callback `fn`262 * as `ext`.263 *264 * By default will `require()` the engine based on the265 * file extension. For example if you try to renderMerge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c
line 266why, one step back266 * a "foo.ejs" file Express will invoke the following internally:Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 267why, one step back267 *Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c
line 268why, one step back268 * app.engine('ejs', require('ejs').__express);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 269–279why, one step back269 *270 * For engines that do not provide `.__express` out of the box,271 * or if you wish to "map" a different extension to the template engine272 * you may use this method. For example mapping the EJS template engine to273 * ".html" files:274 *275 * app.engine('html', require('ejs').renderFile);276 *277 * In this case EJS provides a `.renderFile()` method with278 * the same signature that Express expects: `(path, options, callback)`,279 * though note that it aliases this method as `ejs.__express` internallyMerge tag '4.17.2'Douglas Christopher Wilsonbefore adoptionc7d528c
line 280why, one step back280 * so if you're using ".ejs" extensions you don't need to do anything.Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 281–282why, one step back281 *282 * Some template engines do not follow this convention, thedocs: visionmedia is now tj on GithubDouglas Christopher Wilsonbefore adoptione9539fc
line 283why, one step back283 * [Consolidate.js](https://github.com/tj/consolidate.js)Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 284–290why, one step back284 * library was created to map all of node's popular template285 * engines to follow this convention, thus allowing them to286 * work seamlessly within Express.287 *288 * @param {String} ext289 * @param {Function} fn290 * @return {app} for chainingMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 291why, one step back291 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 292–293why, one step back292 */293Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 294–306why, one step back294app.engine = function engine(ext, fn) {295 if (typeof fn !== 'function') {296 throw new Error('callback function required');297 }298299 // get file extension300 var extension = ext[0] !== '.'301 ? '.' + ext302 : ext;303304 // store engine305 this.engines[extension] = fn;306Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 307–318why, one step back307 return this;308};309310/**311 * Proxy to `Router#param()` with one added api feature. The _name_ parameter312 * can be an array of names.313 *314 * See the Router#param() docs for more details.315 *316 * @param {String|Array} name317 * @param {Function} fn318 * @return {app} for chainingMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 319why, one step back319 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 320–321why, one step back320 */321Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
line 322why, one step back322app.param = function param(name, fn) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 323why, one step back323 if (Array.isArray(name)) {Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
lines 324–326why, one step back324 for (var i = 0; i < name.length; i++) {325 this.param(name[i], fn);326 }Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 327why, one step back327Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 328–330why, one step back328 return this;329 }330Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
line 331why, one step back331 this.router.param(name, fn);Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 332why, one step back332Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 333–339why, one step back333 return this;334};335336/**337 * Assign `setting` to `val`, or return `setting`'s value.338 *339 * app.set('foo', 'bar');Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe
line 340why, one step back340 * app.set('foo');Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 341–347why, one step back341 * // => "bar"342 *343 * Mounted servers inherit their parent server's settings.344 *345 * @param {String} setting346 * @param {*} [val]347 * @return {Server} for chainingMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 348why, one step back348 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 349–350why, one step back349 */350Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 351why, one step back351app.set = function set(setting, val) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 352–353why, one step back352 if (arguments.length === 1) {353 // app.get(setting)Use object with null prototype for settings closes #4835Evan Hahnbefore adoption26801a0
line 354why, one step back354 return this.settings[setting];Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 355–356why, one step back355 }356Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 357–358why, one step back357 debug('set "%s" to %o', setting, val);358Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
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 '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710
lines 372–378why, one step back372373 // trust proxy inherit back-compat374 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {375 configurable: true,376 value: false377 });378Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
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}Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 396why, one step back396 * @privateInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 397–398why, one step back397 */398Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 399why, one step back399app.path = function path() {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
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}Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 417why, one step back417 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 418–419why, one step back418 */419Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 420–421why, one step back420app.enabled = function enabled(setting) {421 return Boolean(this.set(setting));Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
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}Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 436why, one step back436 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 437–438why, one step back437 */438Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 439why, one step back439app.disabled = function disabled(setting) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 440–447why, one step back440 return !this.set(setting);441};442443/**444 * Enable `setting`.445 *446 * @param {String} setting447 * @return {app} for chainingMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 448why, one step back448 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 449–450why, one step back449 */450Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 451why, one step back451app.enable = function enable(setting) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 452–459why, one step back452 return this.set(setting, true);453};454455/**456 * Disable `setting`.457 *458 * @param {String} setting459 * @return {app} for chainingMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 460why, one step back460 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 461–462why, one step back461 */462Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 463why, one step back463app.disable = function disable(setting) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 464–470why, one step back464 return this.set(setting, false);465};466467/**468 * Delegate `.VERB(...)` calls to `router.VERB(...)`.469 */470fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 471–472why, one step back471methods.forEach(function (method) {472 app[method] = function (path) {Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 473–476why, one step back473 if (method === 'get' && arguments.length === 1) {474 // app.get(setting)475 return this.set(path);476 }Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 477why, one step back477Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
line 478why, one step back478 var route = this.route(path);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 479–490why, one step back479 route[method].apply(route, slice.call(arguments, 1));480 return this;481 };482});483484/**485 * Special-cased "all" method, applying the given route `path`,486 * middleware, and callback to _every_ HTTP method.487 *488 * @param {String} path489 * @param {Function} ...490 * @return {app} for chainingMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 491why, one step back491 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 492–493why, one step back492 */493Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 494why, one step back494app.all = function all(path) {Add app.router reference backDouglas Christopher Wilsonbefore adoption509ebb1
line 495why, one step back495 var route = this.route(path);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 496–497why, one step back496 var args = slice.call(arguments, 1);497Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 498–501why, one step back498 for (var i = 0; i < methods.length; i++) {499 route[methods[i]].apply(route, args);500 }501Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 502–516why, one step back502 return this;503};504505/**506 * Render the given view `name` name with `options`507 * and a callback accepting an error and the508 * rendered template string.509 *510 * Example:511 *512 * app.render('email', { name: 'Tobi' }, function(err, html){513 * // ...514 * })515 *516 * @param {String} nameMerge tag '4.13.4'Douglas Christopher Wilsonbefore adoption7cafdb5
line 517why, one step back517 * @param {Object|Function} options or fnMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 518–519why, one step back518 * @param {Function} callback519 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 520–521why, one step back520 */521Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 522why, one step back522app.render = function render(name, options, callback) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 523why, one step back523 var cache = this.cache;Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 524why, one step back524 var done = callback;Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 525why, one step back525 var engines = this.engines;Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 526why, one step back526 var opts = options;Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 527–529why, one step back527 var view;528529 // support callback function as second argMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 530–532why, one step back530 if (typeof options === 'function') {531 done = options;532 opts = {};Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 533–535why, one step back533 }534535 // merge optionsfix: Remove `utils-merge` dependency - use spread syntax instead (#6091)Phillip Bartabefore adoption246f6f5
line 536why, one step back536 var renderOptions = { ...this.locals, ...opts._locals, ...opts };Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 537–538why, one step back537538 // set .cache unless explicitly providedMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 539–541why, one step back539 if (renderOptions.cache == null) {540 renderOptions.cache = this.enabled('view cache');541 }Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 542–543why, one step back542543 // primed cacheMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 544–546why, one step back544 if (renderOptions.cache) {545 view = cache[name];546 }Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 547–549why, one step back547548 // view549 if (!view) {Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 550–552why, one step back550 var View = this.get('view');551552 view = new View(name, {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 553–558why, one step back553 defaultEngine: this.get('view engine'),554 root: this.get('views'),555 engines: engines556 });557558 if (!view.path) {Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 559–562why, one step back559 var dirs = Array.isArray(view.root) && view.root.length > 1560 ? 'directories "' + view.root.slice(0, -1).join('", "') + '" or "' + view.root[view.root.length - 1] + '"'561 : 'directory "' + view.root + '"'562 var err = new Error('Failed to lookup view "' + name + '" in views ' + dirs);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 563why, one step back563 err.view = view;Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 564why, one step back564 return done(err);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 565–567why, one step back565 }566567 // prime the cacheMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 568–570why, one step back568 if (renderOptions.cache) {569 cache[name] = view;570 }Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 571–573why, one step back571 }572573 // renderMerge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 574why, one step back574 tryRender(view, renderOptions, done);Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 575–585why, one step back575};576577/**578 * Listen for connections.579 *580 * A node `http.Server` is returned, with this581 * application (which is a `Function`) as its582 * callback. If you wish to create both an HTTP583 * and HTTPS server you may do so with the "http"584 * and "https" modules as shown here:585 *fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 586–587why, one step back586 * var http = require('node:http')587 * , https = require('node:https')Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 588–594why, one step back588 * , express = require('express')589 * , app = express();590 *591 * http.createServer(app).listen(80);592 * https.createServer({ ... }, app).listen(443);593 *594 * @return {http.Server}Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
line 595why, one step back595 * @publicInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 596–597why, one step back596 */597fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 598why, one step back598app.listen = function listen() {call callback once on listen errorWesbefore adoptionee40a88
lines 599–606why, one step back599 var server = http.createServer(this)600 var args = Array.prototype.slice.call(arguments)601 if (typeof args[args.length - 1] === 'function') {602 var done = args[args.length - 1] = once(args[args.length - 1])603 server.once('error', done)604 }605 return server.listen.apply(server, args)606}Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 607–608why, one step back607608/**Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 609–613why, one step back609 * Log error using console.error.610 *611 * @param {Error} err612 * @private613 */Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 614why, one step back614Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 615–616why, one step back615function logerror(err) {616 /* istanbul ignore next */Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 617why, one step back617 if (this.get('env') !== 'test') console.error(err.stack || err.toString());Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87
lines 618–630why, one step back618}619620/**621 * Try rendering a view.622 * @private623 */624625function tryRender(view, options, callback) {626 try {627 view.render(options, callback);628 } catch (err) {629 callback(err);630 }Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 631why, one step back631}