-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
48 lines (39 loc) · 1.27 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
const express = require('express');
const logger = require('morgan');
const networksRouter = require('./routes/networks');
const exceptionsRouter = require('./routes/exceptions');
const pacRouter = require('./routes/pac');
const getProxyRouter = require('./routes/getproxy');
const swaggerRouter = require('./routes/swagger');
const app = express();
/* connect to db */
const db = require("./db/db");
db.mongoose
.connect(db.url, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log("Connected to the database!");
})
.catch(err => {
console.log("Cannot connect to the database!", err);
process.exit();
});
/* disable X-Powered-By */
app.disable('x-powered-by');
/* middleware */
if (process.env.DEBUG) {
app.use(logger('dev'));
} else {
app.use(logger(':date[iso] :remote-addr :req[x-forwarded-for] ":method :url HTTP/:http-version" :status :res[content-length] :response-time[2] ms ":user-agent"'));
}
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
/* routes */
app.use('/api/v1/networks', networksRouter);
app.use('/api/v1/exceptions', exceptionsRouter);
app.use('/api/v1/getproxyforip', getProxyRouter);
app.use('/pac/wpad.pac', pacRouter);
app.use('/api-docs', swaggerRouter);
module.exports = app;