{"action":"created","issue":{"url":"https://api.github.com/repos/expressjs/express/issues/2828","repository_url":"https://api.github.com/repos/expressjs/express","labels_url":"https://api.github.com/repos/expressjs/express/issues/2828/labels{/name}","comments_url":"https://api.github.com/repos/expressjs/express/issues/2828/comments","events_url":"https://api.github.com/repos/expressjs/express/issues/2828/events","html_url":"https://github.com/expressjs/express/issues/2828","id":122325567,"number":2828,"title":"Feature / Feedback: Private middleware stack per router","user":{"login":"demalus","id":6488033,"avatar_url":"https://avatars.githubusercontent.com/u/6488033?v=3","gravatar_id":"","url":"https://api.github.com/users/demalus","html_url":"https://github.com/demalus","followers_url":"https://api.github.com/users/demalus/followers","following_url":"https://api.github.com/users/demalus/following{/other_user}","gists_url":"https://api.github.com/users/demalus/gists{/gist_id}","starred_url":"https://api.github.com/users/demalus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demalus/subscriptions","organizations_url":"https://api.github.com/users/demalus/orgs","repos_url":"https://api.github.com/users/demalus/repos","events_url":"https://api.github.com/users/demalus/events{/privacy}","received_events_url":"https://api.github.com/users/demalus/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/expressjs/express/labels/discuss","name":"discuss","color":"02d7e1"},{"url":"https://api.github.com/repos/expressjs/express/labels/ideas","name":"ideas","color":"d7e102"},{"url":"https://api.github.com/repos/expressjs/express/labels/module:router","name":"module:router","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2015-12-15T17:36:39Z","updated_at":"2016-02-17T04:47:55Z","closed_at":null,"body":"This feature request is for adding convenience in the following situation: Suppose you have a hierarchy of express apps and want to share middleware per route within a specific app/router.\r\n\r\n```js\r\nvar app = express(),\r\n    middleApp = express(),\r\n    leafApp = express();\r\n\r\napp.use(function(req, res, next) {\r\n  // some global middleware\r\n  next();\r\n});\r\n\r\napp.use('/middle', middleApp);\r\nmiddleApp.use('/leaf', leafApp);\r\n\r\nvar commonMiddleware = function(req, res, next) {\r\n  // some private stuff that should only happen in middleApp\r\n  next();\r\n});\r\n\r\nmiddleApp.get('/something', commonMiddleware, function(req, res) { ... });\r\nmiddleApp.get('/another', commonMiddleware, function(req, res) { ... });\r\n\r\nleafApp.get('/evenmore', function(req, res) { ... });\r\n```\r\n\r\nI think it would be nice if `.use()` could be used to store middleware that is only executed by routes within a given app/router, something like this:\r\n\r\n```js\r\nmiddleApp.use(function(req, res, next) {\r\n  // something only executed by routes within middleApp\r\n  next();\r\n}, true);\r\n```\r\n\r\nIs this something that might be useful for others, or do you feel there's a better way to accomplish this?  It becomes more useful if there's many routes.  I've got an implementation of it [here](https://github.com/demalus/express/tree/feature/private-middleware-stack) if you'd like to see it in action."},"comment":{"url":"https://api.github.com/repos/expressjs/express/issues/comments/185020919","html_url":"https://github.com/expressjs/express/issues/2828#issuecomment-185020919","issue_url":"https://api.github.com/repos/expressjs/express/issues/2828","id":185020919,"user":{"login":"demalus","id":6488033,"avatar_url":"https://avatars.githubusercontent.com/u/6488033?v=3","gravatar_id":"","url":"https://api.github.com/users/demalus","html_url":"https://github.com/demalus","followers_url":"https://api.github.com/users/demalus/followers","following_url":"https://api.github.com/users/demalus/following{/other_user}","gists_url":"https://api.github.com/users/demalus/gists{/gist_id}","starred_url":"https://api.github.com/users/demalus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demalus/subscriptions","organizations_url":"https://api.github.com/users/demalus/orgs","repos_url":"https://api.github.com/users/demalus/repos","events_url":"https://api.github.com/users/demalus/events{/privacy}","received_events_url":"https://api.github.com/users/demalus/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T04:47:55Z","updated_at":"2016-02-17T04:47:55Z","body":"Reposted this to [pillarjs/router](https://github.com/pillarjs/router/issues/35)"}}