{"action":"created","issue":{"url":"https://api.github.com/repos/denali-js/denali/issues/147","repository_url":"https://api.github.com/repos/denali-js/denali","labels_url":"https://api.github.com/repos/denali-js/denali/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/denali-js/denali/issues/147/comments","events_url":"https://api.github.com/repos/denali-js/denali/issues/147/events","html_url":"https://github.com/denali-js/denali/pull/147","id":182341184,"number":147,"title":"WIP: feat(router): run middleware layer prior to routing","user":{"login":"acorncom","id":802505,"avatar_url":"https://avatars.githubusercontent.com/u/802505?v=3","gravatar_id":"","url":"https://api.github.com/users/acorncom","html_url":"https://github.com/acorncom","followers_url":"https://api.github.com/users/acorncom/followers","following_url":"https://api.github.com/users/acorncom/following{/other_user}","gists_url":"https://api.github.com/users/acorncom/gists{/gist_id}","starred_url":"https://api.github.com/users/acorncom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acorncom/subscriptions","organizations_url":"https://api.github.com/users/acorncom/orgs","repos_url":"https://api.github.com/users/acorncom/repos","events_url":"https://api.github.com/users/acorncom/events{/privacy}","received_events_url":"https://api.github.com/users/acorncom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-11T18:39:42Z","updated_at":"2016-10-11T20:49:59Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/denali-js/denali/pulls/147","html_url":"https://github.com/denali-js/denali/pull/147","diff_url":"https://github.com/denali-js/denali/pull/147.diff","patch_url":"https://github.com/denali-js/denali/pull/147.patch"},"body":"A middleware I'm using basically defines an action at the Node level.  In order for the middleware to work, I need to add an additional action to my `routes.js` file that I never actually intend to use.\r\n\r\nDo we want to re-jigger our approach here so middleware run prior to route handling?  I'd be inclined to do that and then have routing fail if no routes were found after that."},"comment":{"url":"https://api.github.com/repos/denali-js/denali/issues/comments/253041708","html_url":"https://github.com/denali-js/denali/pull/147#issuecomment-253041708","issue_url":"https://api.github.com/repos/denali-js/denali/issues/147","id":253041708,"user":{"login":"davewasmer","id":707213,"avatar_url":"https://avatars.githubusercontent.com/u/707213?v=3","gravatar_id":"","url":"https://api.github.com/users/davewasmer","html_url":"https://github.com/davewasmer","followers_url":"https://api.github.com/users/davewasmer/followers","following_url":"https://api.github.com/users/davewasmer/following{/other_user}","gists_url":"https://api.github.com/users/davewasmer/gists{/gist_id}","starred_url":"https://api.github.com/users/davewasmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davewasmer/subscriptions","organizations_url":"https://api.github.com/users/davewasmer/orgs","repos_url":"https://api.github.com/users/davewasmer/repos","events_url":"https://api.github.com/users/davewasmer/events{/privacy}","received_events_url":"https://api.github.com/users/davewasmer/received_events","type":"User","site_admin":false},"created_at":"2016-10-11T20:49:59Z","updated_at":"2016-10-11T20:49:59Z","body":"Here's a hypothetical implementation of that MiddlewareAction class:\r\n\r\n```js\r\nclass MiddlewareAction extends Action {\r\n  middleware = null; // subclasses would override this with their middleware fn\r\n  respond() {\r\n    return new Promise((resolve, reject) => {\r\n      let buffer = '';\r\n      let response = new stream.Passthrough();\r\n      response.on('data', (d) => buffer += d);\r\n      response.on('end', () => resolve(buffer));\r\n      this.middleware(this.request, response);\r\n    });\r\n  }\r\n}\r\n```\r\n\r\nThis isn't enough, obviously - `response` would need to provide the additional APIs that the express response object does, on top of implementing the stream interface. But hopefully this get's the point across."}}
{"actor":{"display_login":"davewasmer"}}