{"action":"created","issue":{"url":"https://api.github.com/repos/fac-14/Brickworks-Tollington_Project/issues/77","repository_url":"https://api.github.com/repos/fac-14/Brickworks-Tollington_Project","labels_url":"https://api.github.com/repos/fac-14/Brickworks-Tollington_Project/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/fac-14/Brickworks-Tollington_Project/issues/77/comments","events_url":"https://api.github.com/repos/fac-14/Brickworks-Tollington_Project/issues/77/events","html_url":"https://github.com/fac-14/Brickworks-Tollington_Project/issues/77","id":369923125,"node_id":"MDU6SXNzdWUzNjk5MjMxMjU=","number":77,"title":"Server stuff (Code Review)","user":{"login":"jamiecoe","id":18463718,"node_id":"MDQ6VXNlcjE4NDYzNzE4","avatar_url":"https://avatars3.githubusercontent.com/u/18463718?v=4","gravatar_id":"","url":"https://api.github.com/users/jamiecoe","html_url":"https://github.com/jamiecoe","followers_url":"https://api.github.com/users/jamiecoe/followers","following_url":"https://api.github.com/users/jamiecoe/following{/other_user}","gists_url":"https://api.github.com/users/jamiecoe/gists{/gist_id}","starred_url":"https://api.github.com/users/jamiecoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamiecoe/subscriptions","organizations_url":"https://api.github.com/users/jamiecoe/orgs","repos_url":"https://api.github.com/users/jamiecoe/repos","events_url":"https://api.github.com/users/jamiecoe/events{/privacy}","received_events_url":"https://api.github.com/users/jamiecoe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-10-14T17:17:50Z","updated_at":"2018-10-14T18:01:02Z","closed_at":null,"author_association":"NONE","body":"### Separating routes from `server.js`\r\n\r\nCurrently, `server.js` contains your express setup & middleware, your route definitions and the command to start the server listening. As your app grows, this file could quickly get too big so I would suggest moving routes to a separate file. You could also make use of the [Express Router](https://expressjs.com/en/api.html#express.router) object, which allows you to modularise and easily mount a set of routes on a specific paths. For example:\r\n\r\nCreate a new file - `apiRoutes.js`\r\n```js\r\nconst apiRoutes = require('express').Router();\r\n\r\napiRoutes.post('/create-event', (req, res) => {\r\n   // create-event stuff\r\n})\r\n\r\napiRoutes.post('/getAllEvents', (req, res) => {\r\n   // getAllEvents stuff\r\n})\r\n\r\n// all your api other routes\r\n\r\nmodule.export = apiRoutes;\r\n```\r\n\r\nThen in `server.js`\r\n```js\r\nconst apiRoutes = require('./apiRoutes')\r\n\r\n// all requests which begin with /api will go through to apiRoutes\r\napp.use('/api', apiRoutes); \r\n```\r\n\r\n### Serving up the front-end for non-homepage urls\r\nTry going directly to one of your page sections, without navigating there from the home page. Eg:\r\nhttps://vigorous-swirles-227d32.netlify.com/categories\r\n\r\nAre you seeing a Page Not Found message? This is because currently you are only serving up your `/dist` folder for [calls to your home route](https://github.com/fac-14/Brickworks-Tollington_Project/blob/02b5235d978cc6c910233e7441c193fdd6e0ba03/src/server.js#L8). You can fix this by adding the following route (**Important:** this must come AFTER all your other route definitions):\r\n\r\n```js\r\napp.get('*', (req, res) => {\r\n res.sendFile(path.join(__dirname, '..', 'dist', 'index.html'));\r\n});\r\n``` \r\nThis will serve your front end code for any requests that aren't to your `/api/...` routes. From here, `react-router` will use the url to render the correct components.   "},"comment":{"url":"https://api.github.com/repos/fac-14/Brickworks-Tollington_Project/issues/comments/429647758","html_url":"https://github.com/fac-14/Brickworks-Tollington_Project/issues/77#issuecomment-429647758","issue_url":"https://api.github.com/repos/fac-14/Brickworks-Tollington_Project/issues/77","id":429647758,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTY0Nzc1OA==","user":{"login":"jamiecoe","id":18463718,"node_id":"MDQ6VXNlcjE4NDYzNzE4","avatar_url":"https://avatars3.githubusercontent.com/u/18463718?v=4","gravatar_id":"","url":"https://api.github.com/users/jamiecoe","html_url":"https://github.com/jamiecoe","followers_url":"https://api.github.com/users/jamiecoe/followers","following_url":"https://api.github.com/users/jamiecoe/following{/other_user}","gists_url":"https://api.github.com/users/jamiecoe/gists{/gist_id}","starred_url":"https://api.github.com/users/jamiecoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamiecoe/subscriptions","organizations_url":"https://api.github.com/users/jamiecoe/orgs","repos_url":"https://api.github.com/users/jamiecoe/repos","events_url":"https://api.github.com/users/jamiecoe/events{/privacy}","received_events_url":"https://api.github.com/users/jamiecoe/received_events","type":"User","site_admin":false},"created_at":"2018-10-14T18:01:02Z","updated_at":"2018-10-14T18:01:02Z","author_association":"NONE","body":"You could have a `<Route path ='/server-error' component = {ServerError} />`, where `ServerError` is a component that renders a message telling users there's been a problem with the server.\r\n\r\nThen when you get a 500 response from your server, you can use `this.props.history.push('/server-error');` to redirect the user. \r\n\r\nWe did something similar in one of our [FAC projects](https://github.com/fac-12/peppr/blob/master/client/src/components/App.js). "}}
{"actor":{"display_login":"jamiecoe"}}