express.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Module dependencies.
  3. */
  4. var EventEmitter = require('events').EventEmitter;
  5. var mixin = require('utils-merge');
  6. var proto = require('./application');
  7. var Route = require('./router/route');
  8. var Router = require('./router');
  9. var req = require('./request');
  10. var res = require('./response');
  11. /**
  12. * Expose `createApplication()`.
  13. */
  14. exports = module.exports = createApplication;
  15. /**
  16. * Create an express application.
  17. *
  18. * @return {Function}
  19. * @api public
  20. */
  21. function createApplication() {
  22. var app = function(req, res, next) {
  23. app.handle(req, res, next);
  24. };
  25. mixin(app, proto);
  26. mixin(app, EventEmitter.prototype);
  27. app.request = { __proto__: req, app: app };
  28. app.response = { __proto__: res, app: app };
  29. app.init();
  30. return app;
  31. }
  32. /**
  33. * Expose the prototypes.
  34. */
  35. exports.application = proto;
  36. exports.request = req;
  37. exports.response = res;
  38. /**
  39. * Expose constructors.
  40. */
  41. exports.Route = Route;
  42. exports.Router = Router;
  43. /**
  44. * Expose middleware
  45. */
  46. exports.query = require('./middleware/query');
  47. exports.static = require('serve-static');
  48. /**
  49. * Replace removed middleware with an appropriate error message.
  50. */
  51. [
  52. 'json',
  53. 'urlencoded',
  54. 'bodyParser',
  55. 'compress',
  56. 'cookieSession',
  57. 'session',
  58. 'logger',
  59. 'cookieParser',
  60. 'favicon',
  61. 'responseTime',
  62. 'errorHandler',
  63. 'timeout',
  64. 'methodOverride',
  65. 'vhost',
  66. 'csrf',
  67. 'directory',
  68. 'limit',
  69. 'multipart',
  70. 'staticCache',
  71. ].forEach(function (name) {
  72. Object.defineProperty(exports, name, {
  73. get: function () {
  74. 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.');
  75. },
  76. configurable: true
  77. });
  78. });