2012-01-02 18:22:06 -08:00
/ * !
2016-11-29 18:29:50 -08:00
* express
* Copyright ( c ) 2009 - 2013 TJ Holowaychuk
* Copyright ( c ) 2013 Roman Shtylman
* Copyright ( c ) 2014 - 2015 Douglas Christopher Wilson
2012-01-02 18:22:06 -08:00
* MIT Licensed
* /
2016-11-29 18:29:50 -08:00
'use strict' ;
2012-01-02 18:22:06 -08:00
/ * *
2016-11-29 18:29:50 -08:00
* Module dependencies .
2012-01-02 18:22:06 -08:00
* /
2019-04-13 14:44:10 -04:00
var bodyParser = require ( 'body-parser' )
2016-11-29 18:29:50 -08:00
var EventEmitter = require ( 'events' ) . EventEmitter ;
var mixin = require ( 'merge-descriptors' ) ;
var proto = require ( './application' ) ;
var Route = require ( './router/route' ) ;
var Router = require ( './router' ) ;
var req = require ( './request' ) ;
var res = require ( './response' ) ;
2012-01-02 18:22:06 -08:00
/ * *
2016-11-29 18:29:50 -08:00
* Expose ` createApplication() ` .
2012-01-02 18:22:06 -08:00
* /
2016-11-29 18:29:50 -08:00
exports = module . exports = createApplication ;
2012-01-02 18:22:06 -08:00
/ * *
2016-11-29 18:29:50 -08:00
* Create an express application .
2012-01-02 18:22:06 -08:00
*
2016-11-29 18:29:50 -08:00
* @ return { Function }
2012-01-02 18:22:06 -08:00
* @ api public
* /
2016-11-29 18:29:50 -08:00
function createApplication ( ) {
var app = function ( req , res , next ) {
app . handle ( req , res , next ) ;
} ;
2012-01-02 18:22:06 -08:00
2016-11-29 18:29:50 -08:00
mixin ( app , EventEmitter . prototype , false ) ;
mixin ( app , proto , false ) ;
2012-01-02 18:22:06 -08:00
2019-04-13 14:44:10 -04: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 }
} )
2016-11-29 18:29:50 -08:00
app . init ( ) ;
return app ;
}
2012-01-02 18:22:06 -08:00
/ * *
2016-11-29 18:29:50 -08:00
* Expose the prototypes .
2012-01-02 18:22:06 -08:00
* /
2016-11-29 18:29:50 -08:00
exports . application = proto ;
exports . request = req ;
exports . response = res ;
2012-01-02 18:22:06 -08:00
/ * *
2016-11-29 18:29:50 -08:00
* Expose constructors .
2012-01-02 18:22:06 -08:00
* /
2016-11-29 18:29:50 -08:00
exports . Route = Route ;
exports . Router = Router ;
2012-01-02 18:22:06 -08:00
/ * *
2016-11-29 18:29:50 -08:00
* Expose middleware
2012-01-02 18:22:06 -08:00
* /
2019-04-13 14:44:10 -04:00
exports . json = bodyParser . json
2016-11-29 18:29:50 -08:00
exports . query = require ( './middleware/query' ) ;
exports . static = require ( 'serve-static' ) ;
2019-04-13 14:44:10 -04:00
exports . urlencoded = bodyParser . urlencoded
2012-01-02 18:22:06 -08:00
2016-11-29 18:29:50 -08:00
/ * *
* Replace removed middleware with an appropriate error message .
* /
2012-01-02 18:22:06 -08:00
2019-04-13 14:44:10 -04:00
var removedMiddlewares = [
2016-11-29 18:29:50 -08:00
'bodyParser' ,
'compress' ,
'cookieSession' ,
'session' ,
'logger' ,
'cookieParser' ,
'favicon' ,
'responseTime' ,
'errorHandler' ,
'timeout' ,
'methodOverride' ,
'vhost' ,
'csrf' ,
'directory' ,
'limit' ,
'multipart' ,
2019-04-13 14:44:10 -04:00
'staticCache'
]
removedMiddlewares . forEach ( function ( name ) {
2016-11-29 18:29:50 -08:00
Object . defineProperty ( exports , name , {
get : function ( ) {
throw new Error ( 'Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.' ) ;
} ,
configurable : true
} ) ;
} ) ;