-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
35 lines (27 loc) · 992 Bytes
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//the base application router.
const path = require('path');
const config = require(path.join(__dirname, '/config/index.js'));
const logger = config.logger.createLogger('routes');
const router = require('express').Router();
const errorObject = require.cache.userObject.errorObject;
//prining the details of any requests being made to the application.
router.use('/', (req, res, next) => {
logger.debug(`METHOD: ${req.method} URL: ${req.url}`);
next();
});
//attaching other routes to the base router.
router.use('/sample', require(path.join(__dirname, '/user_modules/sample/routes.js')));
//not found
router.use('/', (req, res) => {
const errObj = errorObject.getError('PAGE_NOT_FOUND');
res.statusCode = errObj.status;
res.json(errObj.errorMessage);
});
//error
router.use('/', (err, req, res) => {
const errObj = errorObject.getError('SERVER_ERROR');
res.statusCode = errObj.status;
res.json(errObj.errorMessage);
logger.error(err);
});
module.exports = router;