Skip to content

Commit

Permalink
Merge pull request #14 from beevk/feature/#11-routes
Browse files Browse the repository at this point in the history
#11-add routes and controllers
  • Loading branch information
beevk authored May 28, 2021
2 parents cca083f + f7d25ce commit 93efd02
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"scripts": {
"dev": "nodemon source/server.ts",
"start": "node build/server.js",
"build": "rm -rf build/ && tsc",
"clean": "rm -rf build",
"lint": "eslint . --ext .ts,.js --quiet --fix"
Expand Down
11 changes: 11 additions & 0 deletions source/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { RequestHandler } from 'express';

const getStatus: RequestHandler = (_req, res) => {
return res.status(200).json({ data: 'Ok' });
};

const headStatus: RequestHandler = (_req, res) => {
return res.status(200).end();
};

export { getStatus, headStatus };
16 changes: 7 additions & 9 deletions source/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import express from 'express';
import express, { RequestHandler } from 'express';

import { getStatus, headStatus } from '../controllers';
import v1Routes from './v1';

const router = express.Router();

// Routes for health check
router.head('/status', (_req, res) => {
return res.status(200).end();
});
router.get('/status', (_req, res) => {
return res.status(200).json({ data: 'Ok' });
});
router.head('/status', headStatus);
router.get('/status', getStatus);

// Keep on adding routes like this
router.use('/v1', v1Routes);

/** Error - 404 */
router.use((_req, res, _next) => {
const notFoundController: RequestHandler = (_req, res) => {
const error = new Error('Path Not found');
return res.status(404).json({
message: error.message
});
});
};
router.use(notFoundController);

export default router;

0 comments on commit 93efd02

Please sign in to comment.