{"action":"created","issue":{"url":"https://api.github.com/repos/zeit/next.js/issues/25","repository_url":"https://api.github.com/repos/zeit/next.js","labels_url":"https://api.github.com/repos/zeit/next.js/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/zeit/next.js/issues/25/comments","events_url":"https://api.github.com/repos/zeit/next.js/issues/25/events","html_url":"https://github.com/zeit/next.js/issues/25","id":183300051,"number":25,"title":"Custom server logic / routing","user":{"login":"rauchg","id":13041,"avatar_url":"https://avatars.githubusercontent.com/u/13041?v=3","gravatar_id":"","url":"https://api.github.com/users/rauchg","html_url":"https://github.com/rauchg","followers_url":"https://api.github.com/users/rauchg/followers","following_url":"https://api.github.com/users/rauchg/following{/other_user}","gists_url":"https://api.github.com/users/rauchg/gists{/gist_id}","starred_url":"https://api.github.com/users/rauchg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rauchg/subscriptions","organizations_url":"https://api.github.com/users/rauchg/orgs","repos_url":"https://api.github.com/users/rauchg/repos","events_url":"https://api.github.com/users/rauchg/events{/privacy}","received_events_url":"https://api.github.com/users/rauchg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zeit/next.js/labels/exploration","name":"exploration","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-16T23:29:44Z","updated_at":"2016-10-26T02:30:41Z","closed_at":null,"body":"```bash\r\nnext -s server.js\r\n```\r\n\r\nor in `package.json`:\r\n\r\n```json\r\n{\r\n  \"next\": {\r\n    \"serverHandler\": \"./server.js\"\r\n  }\r\n}\r\n```\r\n\r\nLet's say you want to override the default mapping between filesystem and route, you could set up something like this:\r\n\r\n```js\r\nconst { renderComponent } = require('next/server')\r\nmodule.exports = ({ path, req, res }) => {\r\n  if ('/a' === path) {\r\n    return renderComponent(req, './b')\r\n  }\r\n}\r\n```\r\n\r\nThe function would receive a context object with the following properties (as far as I have thought about it):\r\n- `path` the intended path of the request. This is so that if we request `/a.json` or `/a`, the path is still `/a`, which simplifies the logic for the programmer\r\n- `req` the original request from node\r\n- `res` the original response from node\r\n\r\nThe return value can be a `Promise`. If `undefined` is returned, it performs the default behavior.\r\nThis file provides an opportunity to short-circuit (like send a `301`), add global security / authentication requirements, etc.\r\n\r\n[1] We might or might not want to transpile this file. Since it's \"server-only\", I think it's ok to assume it just supports whatever the version of Node.js you're running. "},"comment":{"url":"https://api.github.com/repos/zeit/next.js/issues/comments/256233645","html_url":"https://github.com/zeit/next.js/issues/25#issuecomment-256233645","issue_url":"https://api.github.com/repos/zeit/next.js/issues/25","id":256233645,"user":{"login":"malixsys","id":664650,"avatar_url":"https://avatars.githubusercontent.com/u/664650?v=3","gravatar_id":"","url":"https://api.github.com/users/malixsys","html_url":"https://github.com/malixsys","followers_url":"https://api.github.com/users/malixsys/followers","following_url":"https://api.github.com/users/malixsys/following{/other_user}","gists_url":"https://api.github.com/users/malixsys/gists{/gist_id}","starred_url":"https://api.github.com/users/malixsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malixsys/subscriptions","organizations_url":"https://api.github.com/users/malixsys/orgs","repos_url":"https://api.github.com/users/malixsys/repos","events_url":"https://api.github.com/users/malixsys/events{/privacy}","received_events_url":"https://api.github.com/users/malixsys/received_events","type":"User","site_admin":false},"created_at":"2016-10-26T02:30:41Z","updated_at":"2016-10-26T02:30:41Z","body":"Might be easier to have a convention on say `/api/*` matching .js files in a server directory...\r\nMaybe also supporting some koa/express type middleware insertion/signature (req, res, next) => ?"}}
{"actor":{"display_login":"malixsys"}}