-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
35 lines (29 loc) · 917 Bytes
/
app.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
35
require('dotenv/config');
const express = require('express');
const middlewares = require('./src/middleware');
const app = express();
const glob = require('glob');
// custom logger
const appLogger = require('./src/utils/logger');
global.__basedir = __dirname;
app.use(appLogger.requestDetails(appLogger));
// const authenticate = require('./utils/authenticate');
app.enable('trust proxy');
middlewares(app);
/* Router setup */
const openRouter = express.Router(); // Open routes
const apiRouter = express.Router(); // Protected routes
/* Fetch router files and apply them to our routers */
glob('./src/components/*', null, (err, items) => {
items.forEach(component => {
if (require(component).routes) require(component).routes(
openRouter,
apiRouter,
);
});
});
// Admin Panel Routes
app.use('/v1', openRouter);
app.use('/api/v1', apiRouter);
// exporting the app
module.exports = app;