twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

express.js (2409B)


      1 /*!
      2  * express
      3  * Copyright(c) 2009-2013 TJ Holowaychuk
      4  * Copyright(c) 2013 Roman Shtylman
      5  * Copyright(c) 2014-2015 Douglas Christopher Wilson
      6  * MIT Licensed
      7  */
      8 
      9 'use strict';
     10 
     11 /**
     12  * Module dependencies.
     13  */
     14 
     15 var bodyParser = require('body-parser')
     16 var EventEmitter = require('events').EventEmitter;
     17 var mixin = require('merge-descriptors');
     18 var proto = require('./application');
     19 var Route = require('./router/route');
     20 var Router = require('./router');
     21 var req = require('./request');
     22 var res = require('./response');
     23 
     24 /**
     25  * Expose `createApplication()`.
     26  */
     27 
     28 exports = module.exports = createApplication;
     29 
     30 /**
     31  * Create an express application.
     32  *
     33  * @return {Function}
     34  * @api public
     35  */
     36 
     37 function createApplication() {
     38   var app = function(req, res, next) {
     39     app.handle(req, res, next);
     40   };
     41 
     42   mixin(app, EventEmitter.prototype, false);
     43   mixin(app, proto, false);
     44 
     45   // expose the prototype that will get set on requests
     46   app.request = Object.create(req, {
     47     app: { configurable: true, enumerable: true, writable: true, value: app }
     48   })
     49 
     50   // expose the prototype that will get set on responses
     51   app.response = Object.create(res, {
     52     app: { configurable: true, enumerable: true, writable: true, value: app }
     53   })
     54 
     55   app.init();
     56   return app;
     57 }
     58 
     59 /**
     60  * Expose the prototypes.
     61  */
     62 
     63 exports.application = proto;
     64 exports.request = req;
     65 exports.response = res;
     66 
     67 /**
     68  * Expose constructors.
     69  */
     70 
     71 exports.Route = Route;
     72 exports.Router = Router;
     73 
     74 /**
     75  * Expose middleware
     76  */
     77 
     78 exports.json = bodyParser.json
     79 exports.query = require('./middleware/query');
     80 exports.raw = bodyParser.raw
     81 exports.static = require('serve-static');
     82 exports.text = bodyParser.text
     83 exports.urlencoded = bodyParser.urlencoded
     84 
     85 /**
     86  * Replace removed middleware with an appropriate error message.
     87  */
     88 
     89 var removedMiddlewares = [
     90   'bodyParser',
     91   'compress',
     92   'cookieSession',
     93   'session',
     94   'logger',
     95   'cookieParser',
     96   'favicon',
     97   'responseTime',
     98   'errorHandler',
     99   'timeout',
    100   'methodOverride',
    101   'vhost',
    102   'csrf',
    103   'directory',
    104   'limit',
    105   'multipart',
    106   'staticCache'
    107 ]
    108 
    109 removedMiddlewares.forEach(function (name) {
    110   Object.defineProperty(exports, name, {
    111     get: function () {
    112       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.');
    113     },
    114     configurable: true
    115   });
    116 });