{"action":"opened","issue":{"url":"https://api.github.com/repos/steida/este/issues/218","labels_url":"https://api.github.com/repos/steida/este/issues/218/labels{/name}","comments_url":"https://api.github.com/repos/steida/este/issues/218/comments","events_url":"https://api.github.com/repos/steida/este/issues/218/events","html_url":"https://github.com/steida/este/issues/218","id":77643559,"number":218,"title":"Refactor server","user":{"login":"grabbou","id":2464966,"avatar_url":"https://avatars.githubusercontent.com/u/2464966?v=3","gravatar_id":"","url":"https://api.github.com/users/grabbou","html_url":"https://github.com/grabbou","followers_url":"https://api.github.com/users/grabbou/followers","following_url":"https://api.github.com/users/grabbou/following{/other_user}","gists_url":"https://api.github.com/users/grabbou/gists{/gist_id}","starred_url":"https://api.github.com/users/grabbou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grabbou/subscriptions","organizations_url":"https://api.github.com/users/grabbou/orgs","repos_url":"https://api.github.com/users/grabbou/repos","events_url":"https://api.github.com/users/grabbou/events{/privacy}","received_events_url":"https://api.github.com/users/grabbou/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-18T12:44:16Z","updated_at":"2015-05-18T12:44:16Z","closed_at":null,"body":"The server needs to be refactored. The idea is to take all the goodies and features provided by middlewares and use them wherever possible. Instead of having all files living in the `server` folder which makes it quite hard to add new bits like API endpoints, I suggest using sub-apps which will allow quick spawning of new elements.\r\n\r\nPlan:\r\n- Move all React related things (render, html) to a `frontend` directory inside a server. This sub-app will take care of displaying the frontend + compressing files and exposing static files as well.\r\n- Move all React realted middlewares like compression() to the above subapp\r\n- Make a new sub-app called api (proof of concept, just to show the approach) that will have `handlers` folder in which, there are going to be `controllers/routes`. Each file in that folder will expose a `router` so they are not only able to apply app specific middlewares but also route specific ones.\r\n- Add all sub-app specific middlewares to it (like `bodyParser.json()` or `cors()).\r\n- Expose a test endpoint, let's say `GET /v1/todos` that, based on params will return a random number of todos + `POST /v1/auth/login` (no need to fake auth stuff anymore)\r\n\r\nThe good think about using sub-apps is if our users do not want to use `este.js` backend for handling socket.io/auth/custom api calls, they can just remove `api` folder and deregister the middleware and they are good to go. No need to debug the code and check the errors."}}