{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/sails/issues/3477","labels_url":"https://api.github.com/repos/balderdashy/sails/issues/3477/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/sails/issues/3477/comments","events_url":"https://api.github.com/repos/balderdashy/sails/issues/3477/events","html_url":"https://github.com/balderdashy/sails/issues/3477","id":125665778,"number":3477,"title":"Issue with middleware?","user":{"login":"zaiddag","id":1861264,"avatar_url":"https://avatars.githubusercontent.com/u/1861264?v=3","gravatar_id":"","url":"https://api.github.com/users/zaiddag","html_url":"https://github.com/zaiddag","followers_url":"https://api.github.com/users/zaiddag/followers","following_url":"https://api.github.com/users/zaiddag/following{/other_user}","gists_url":"https://api.github.com/users/zaiddag/gists{/gist_id}","starred_url":"https://api.github.com/users/zaiddag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zaiddag/subscriptions","organizations_url":"https://api.github.com/users/zaiddag/orgs","repos_url":"https://api.github.com/users/zaiddag/repos","events_url":"https://api.github.com/users/zaiddag/events{/privacy}","received_events_url":"https://api.github.com/users/zaiddag/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-01-08T18:27:26Z","updated_at":"2016-01-09T00:29:34Z","closed_at":"2016-01-09T00:20:10Z","body":"I'm pretty sure this is just a docs problem or something, but I added morgan logging middleware, and the middleware is never hit\r\n\r\nI added the middleware funcs to config.http.middleware and added their keys to middleware.order\r\n\r\n```javascript\r\nvar morgan = require('morgan')\r\nvar fs = require('fs')\r\n\r\nmodule.exports.http = {\r\n  middleware: {\r\n\r\n    'morganfile':function(req, res, next) {\r\n      console.log('got middleware hit')\r\n    },\r\n    'morganconsole':morgan('combined'),\r\n\r\n    order: [\r\n       'startRequestTimer',\r\n       'cookieParser',\r\n       'session',\r\n       'myRequestLogger',\r\n       'bodyParser',\r\n       'handleBodyParserError',\r\n       'compress',\r\n       'methodOverride',\r\n       'poweredBy',\r\n       '$custom',\r\n       'router',\r\n       'www',\r\n       'favicon',\r\n       '404',\r\n       '500',\r\n       'morganfile',\r\n       'morganconsole',\r\n       'maybefail'\r\n     ],\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/balderdashy/sails/issues/comments/170168860","html_url":"https://github.com/balderdashy/sails/issues/3477#issuecomment-170168860","issue_url":"https://api.github.com/repos/balderdashy/sails/issues/3477","id":170168860,"user":{"login":"mikermcneil","id":618009,"avatar_url":"https://avatars.githubusercontent.com/u/618009?v=3","gravatar_id":"","url":"https://api.github.com/users/mikermcneil","html_url":"https://github.com/mikermcneil","followers_url":"https://api.github.com/users/mikermcneil/followers","following_url":"https://api.github.com/users/mikermcneil/following{/other_user}","gists_url":"https://api.github.com/users/mikermcneil/gists{/gist_id}","starred_url":"https://api.github.com/users/mikermcneil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikermcneil/subscriptions","organizations_url":"https://api.github.com/users/mikermcneil/orgs","repos_url":"https://api.github.com/users/mikermcneil/repos","events_url":"https://api.github.com/users/mikermcneil/events{/privacy}","received_events_url":"https://api.github.com/users/mikermcneil/received_events","type":"User","site_admin":false},"created_at":"2016-01-09T00:29:34Z","updated_at":"2016-01-09T00:29:34Z","body":"@sgress454 :house:  :bread: \r\n\r\n@zaiddag if you you try moving morgan up to where `myRequestLogger` is, I think you'll get the desired effect.\r\n\r\nMore docs available here:\r\n+ http://sailsjs.org/documentation/concepts/middleware\r\n+ http://sailsjs.org/documentation/reference/configuration/sails-config-http#?properties\r\n\r\n\r\n@zaiddag ^^ however I noticed after looking over those docs that none of them really properly explain what the `order` is really doing.  Basically, the way http middleware works in Sails/Express is this:\r\n\r\n1. an HTTP request comes in\r\n2. plop into the first middleware (`startRequestTimer`)  When that middleware calls `next()`...\r\n3. plop down down to the next middleware in the configured `order` -- i.e. `cookieParser()`.  When that middleware calls `next()`...\r\n... and so forth.\r\n\r\nThe reason why 500 is at the very end is an artifact of how express handles the middleware chain.  If an HTTP middleware function has a fourth argument after `next()`, it is understood to be a catchall error handler.  In our order, we put 500 at the very end for clarity.  Right above it is `404`, a normal middleware (3 arguments), that is the very last normal middleware in the `order`.  This is used when absolutely nothing matches a requested URL (e.g. if you're maintaining an e-commerce API for a doorknob manufacturer, the `404` middleware might run if someone is sending requests `POST /portholes/37/break?with=hammer` or `DELETE /kleenexbox/1048`).\r\n"}}