Tuesday 16 May 2017

Where in the Express source is router.get function defined?

I wanted to see the implementation of express.Router.get.

I looked at the express source on git, starting with the project's index.js.

The index has module.exports = require('./lib/express'). That file has var Router = require('./router'). That location is a directory, so I checked the index.js file in that directory. Sure enough it has:

var proto = module.exports = function(options) {
  var opts = options || {};

  function router(req, res, next) {
    router.handle(req, res, next);
  }

  // mixin Router class functions
  setPrototypeOf(router, proto)

  router.params = {};
  router._params = [];
  router.caseSensitive = opts.caseSensitive;
  router.mergeParams = opts.mergeParams;
  router.strict = opts.strict;
  router.stack = [];

  return router;
};

That's the code that returns the router function. However, there is no .get function defined anywhere. Where is the actual function defined?

Note: I'm asking about the get function you would use like: router.get('/', ...).



via King of the Bit

No comments:

Post a Comment