2015-06-18 23:00:20 -04:00
|
|
|
/*!
|
|
|
|
|
* express
|
|
|
|
|
* Copyright(c) 2009-2013 TJ Holowaychuk
|
|
|
|
|
* Copyright(c) 2013 Roman Shtylman
|
|
|
|
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
|
|
|
* MIT Licensed
|
|
|
|
|
*/
|
|
|
|
|
|
2015-06-18 23:01:18 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2011-03-01 10:54:04 -08:00
|
|
|
/**
|
|
|
|
|
* Module dependencies.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-28 13:22:36 -04:00
|
|
|
var bodyParser = require('body-parser')
|
2024-12-21 22:58:33 +01:00
|
|
|
var EventEmitter = require('node:events').EventEmitter;
|
2014-10-22 15:18:10 -04:00
|
|
|
var mixin = require('merge-descriptors');
|
2014-03-25 15:23:04 -07:00
|
|
|
var proto = require('./application');
|
2015-07-06 23:46:00 -04:00
|
|
|
var Router = require('router');
|
2014-03-25 15:23:04 -07:00
|
|
|
var req = require('./request');
|
|
|
|
|
var res = require('./response');
|
2011-10-07 09:23:54 -07:00
|
|
|
|
2011-10-07 10:01:30 -07:00
|
|
|
/**
|
|
|
|
|
* Expose `createApplication()`.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
exports = module.exports = createApplication;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create an express application.
|
|
|
|
|
*
|
|
|
|
|
* @return {Function}
|
|
|
|
|
* @api public
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function createApplication() {
|
2014-01-25 17:57:25 -05:00
|
|
|
var app = function(req, res, next) {
|
|
|
|
|
app.handle(req, res, next);
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-01 16:33:09 -05:00
|
|
|
mixin(app, EventEmitter.prototype, false);
|
|
|
|
|
mixin(app, proto, false);
|
2014-01-25 17:57:25 -05:00
|
|
|
|
2017-02-23 01:52:49 -05:00
|
|
|
// expose the prototype that will get set on requests
|
|
|
|
|
app.request = Object.create(req, {
|
|
|
|
|
app: { configurable: true, enumerable: true, writable: true, value: app }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// expose the prototype that will get set on responses
|
|
|
|
|
app.response = Object.create(res, {
|
|
|
|
|
app: { configurable: true, enumerable: true, writable: true, value: app }
|
|
|
|
|
})
|
|
|
|
|
|
2011-10-07 09:29:36 -07:00
|
|
|
app.init();
|
2011-10-07 09:23:54 -07:00
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-07 13:13:32 -07:00
|
|
|
/**
|
2011-11-28 11:48:27 -08:00
|
|
|
* Expose the prototypes.
|
2011-10-07 13:13:32 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
exports.application = proto;
|
2011-11-28 11:48:27 -08:00
|
|
|
exports.request = req;
|
|
|
|
|
exports.response = res;
|
2011-10-07 13:13:32 -07:00
|
|
|
|
2011-10-07 10:01:30 -07:00
|
|
|
/**
|
|
|
|
|
* Expose constructors.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-06 23:46:00 -04:00
|
|
|
exports.Route = Router.Route;
|
2011-12-06 16:36:52 -08:00
|
|
|
exports.Router = Router;
|
2011-10-07 10:01:30 -07:00
|
|
|
|
2014-02-15 20:20:12 -05:00
|
|
|
/**
|
|
|
|
|
* Expose middleware
|
|
|
|
|
*/
|
2011-03-30 21:59:15 -07:00
|
|
|
|
2017-09-28 13:22:36 -04:00
|
|
|
exports.json = bodyParser.json
|
2018-08-08 07:42:00 +03:00
|
|
|
exports.raw = bodyParser.raw
|
2014-03-05 21:58:49 -08:00
|
|
|
exports.static = require('serve-static');
|
2017-10-23 18:00:19 +03:00
|
|
|
exports.text = bodyParser.text
|
2017-09-28 13:22:36 -04:00
|
|
|
exports.urlencoded = bodyParser.urlencoded
|