You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
1.9 KiB

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