Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

express.js 2.4KB

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