Revert "Changements dans les modules (nouvelle version Express, mysql, ..)"

This reverts commit bdab795506.
This commit is contained in:
2023-11-23 16:13:50 +01:00
parent 756f928ced
commit 5b0d68d66f
818 changed files with 35968 additions and 82263 deletions

View File

@@ -14,17 +14,28 @@
*/
var finalhandler = require('finalhandler');
var Router = require('./router');
var methods = require('methods');
var middleware = require('./middleware/init');
var query = require('./middleware/query');
var debug = require('debug')('express:application');
var View = require('./view');
var http = require('http');
var compileETag = require('./utils').compileETag;
var compileQueryParser = require('./utils').compileQueryParser;
var compileTrust = require('./utils').compileTrust;
var deprecate = require('depd')('express');
var flatten = require('array-flatten');
var merge = require('utils-merge');
var resolve = require('path').resolve;
var Router = require('router');
var setPrototypeOf = require('setprototypeof')
/**
* Module variables.
* @private
*/
var hasOwnProperty = Object.prototype.hasOwnProperty
var slice = Array.prototype.slice;
/**
@@ -51,29 +62,11 @@ var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';
*/
app.init = function init() {
var router = null;
this.cache = {};
this.engines = {};
this.settings = {};
this.defaultConfiguration();
// Setup getting to lazily add base router
Object.defineProperty(this, 'router', {
configurable: true,
enumerable: true,
get: function getrouter() {
if (router === null) {
router = new Router({
caseSensitive: this.enabled('case sensitive routing'),
strict: this.enabled('strict routing')
});
}
return router;
}
});
};
/**
@@ -109,10 +102,10 @@ app.defaultConfiguration = function defaultConfiguration() {
}
// inherit protos
this.request.__proto__ = parent.request;
this.response.__proto__ = parent.response;
this.engines.__proto__ = parent.engines;
this.settings.__proto__ = parent.settings;
setPrototypeOf(this.request, parent.request)
setPrototypeOf(this.response, parent.response)
setPrototypeOf(this.engines, parent.engines)
setPrototypeOf(this.settings, parent.settings)
});
// setup locals
@@ -132,6 +125,32 @@ app.defaultConfiguration = function defaultConfiguration() {
if (env === 'production') {
this.enable('view cache');
}
Object.defineProperty(this, 'router', {
get: function() {
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.');
}
});
};
/**
* lazily adds the base router if it has not yet been added.
*
* We cannot add the base router in the defaultConfiguration because
* it reads app settings which might be set after that has run.
*
* @private
*/
app.lazyrouter = function lazyrouter() {
if (!this._router) {
this._router = new Router({
caseSensitive: this.enabled('case sensitive routing'),
strict: this.enabled('strict routing')
});
this._router.use(query(this.get('query parser fn')));
this._router.use(middleware.init(this));
}
};
/**
@@ -144,31 +163,22 @@ app.defaultConfiguration = function defaultConfiguration() {
*/
app.handle = function handle(req, res, callback) {
var router = this._router;
// final handler
var done = callback || finalhandler(req, res, {
env: this.get('env'),
onerror: logerror.bind(this)
});
// set powered by header
if (this.enabled('x-powered-by')) {
res.setHeader('X-Powered-By', 'Express');
// no routes
if (!router) {
debug('no routes defined on app');
done();
return;
}
// set circular references
req.res = res;
res.req = req;
// alter the prototypes
req.__proto__ = this.request;
res.__proto__ = this.response;
// setup locals
if (!res.locals) {
res.locals = Object.create(null);
}
this.router.handle(req, res, done);
router.handle(req, res, done);
};
/**
@@ -204,11 +214,12 @@ app.use = function use(fn) {
var fns = flatten(slice.call(arguments, offset));
if (fns.length === 0) {
throw new TypeError('app.use() requires middleware functions');
throw new TypeError('app.use() requires a middleware function')
}
// get router
var router = this.router;
// setup router
this.lazyrouter();
var router = this._router;
fns.forEach(function (fn) {
// non-express app
@@ -224,8 +235,8 @@ app.use = function use(fn) {
router.use(path, function mounted_app(req, res, next) {
var orig = req.app;
fn.handle(req, res, function (err) {
req.__proto__ = orig.request;
res.__proto__ = orig.response;
setPrototypeOf(req, orig.request)
setPrototypeOf(res, orig.response)
next(err);
});
});
@@ -248,7 +259,8 @@ app.use = function use(fn) {
*/
app.route = function route(path) {
return this.router.route(path);
this.lazyrouter();
return this._router.route(path);
};
/**
@@ -257,9 +269,9 @@ app.route = function route(path) {
*
* By default will `require()` the engine based on the
* file extension. For example if you try to render
* a "foo.jade" file Express will invoke the following internally:
* a "foo.ejs" file Express will invoke the following internally:
*
* app.engine('jade', require('jade').__express);
* app.engine('ejs', require('ejs').__express);
*
* For engines that do not provide `.__express` out of the box,
* or if you wish to "map" a different extension to the template engine
@@ -271,7 +283,7 @@ app.route = function route(path) {
* In this case EJS provides a `.renderFile()` method with
* the same signature that Express expects: `(path, options, callback)`,
* though note that it aliases this method as `ejs.__express` internally
* so if you're using ".ejs" extensions you dont need to do anything.
* so if you're using ".ejs" extensions you don't need to do anything.
*
* Some template engines do not follow this convention, the
* [Consolidate.js](https://github.com/tj/consolidate.js)
@@ -314,6 +326,8 @@ app.engine = function engine(ext, fn) {
*/
app.param = function param(name, fn) {
this.lazyrouter();
if (Array.isArray(name)) {
for (var i = 0; i < name.length; i++) {
this.param(name[i], fn);
@@ -322,7 +336,7 @@ app.param = function param(name, fn) {
return this;
}
this.router.param(name, fn);
this._router.param(name, fn);
return this;
};
@@ -331,7 +345,7 @@ app.param = function param(name, fn) {
* Assign `setting` to `val`, or return `setting`'s value.
*
* app.set('foo', 'bar');
* app.get('foo');
* app.set('foo');
* // => "bar"
*
* Mounted servers inherit their parent server's settings.
@@ -345,7 +359,17 @@ app.param = function param(name, fn) {
app.set = function set(setting, val) {
if (arguments.length === 1) {
// app.get(setting)
return this.settings[setting];
var settings = this.settings
while (settings && settings !== Object.prototype) {
if (hasOwnProperty.call(settings, setting)) {
return settings[setting]
}
settings = Object.getPrototypeOf(settings)
}
return undefined
}
debug('set "%s" to %o', setting, val);
@@ -469,7 +493,9 @@ methods.forEach(function(method){
return this.set(path);
}
var route = this.route(path);
this.lazyrouter();
var route = this._router.route(path);
route[method].apply(route, slice.call(arguments, 1));
return this;
};
@@ -486,7 +512,9 @@ methods.forEach(function(method){
*/
app.all = function all(path) {
var route = this.route(path);
this.lazyrouter();
var route = this._router.route(path);
var args = slice.call(arguments, 1);
for (var i = 0; i < methods.length; i++) {
@@ -496,6 +524,10 @@ app.all = function all(path) {
return this;
};
// del -> delete alias
app.del = deprecate.function(app.delete, 'app.del: Use app.delete instead');
/**
* Render the given view `name` name with `options`
* and a callback accepting an error and the
@@ -508,7 +540,7 @@ app.all = function all(path) {
* })
*
* @param {String} name
* @param {String|Function} options or fn
* @param {Object|Function} options or fn
* @param {Function} callback
* @public
*/