Refactor route logic to app.js. add unit test