-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#11-add routes and controllers
- Loading branch information
Showing
3 changed files
with
19 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |