-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (46 loc) · 1.33 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
require('dotenv/config');
const express = require('express');
const middlewares = require('./src/middleware');
const app = express();
const AccessControl = require('express-ip-access-control');
const glob = require('glob');
require('./src/config/db');
// custom logger
const appLogger = require('./src/utils/logger');
global.__basedir = __dirname;
app.use(appLogger.requestDetails(appLogger));
var options = {
mode: 'deny',
denys: [],
allows: ['**8.1**.1.**'],
forceConnectionAddress: false,
log: function (clientIp, access) {
console.log(clientIp + (access ? ' accessed.' : ' denied.'));
},
statusCode: 401,
redirectTo: '',
message: 'Unauthorized'
};
const middleware = AccessControl(options);
app.use(middleware);
// 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;