-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·46 lines (34 loc) · 989 Bytes
/
server.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
var express = require('express');
var morgan = require('morgan')
var cors = require('cors');
var rfs = require('rotating-file-stream')
var config = require('./config');
var app = express();
// Morgan logs
if (config.log.output) {
// create a rotating write stream
var accessLogStream = rfs('access.log', {
interval: '1d', // rotate daily
path: 'logs'
})
// setup the logger
app.use(morgan(config.log.type, { stream: accessLogStream }))
} else {
app.use(morgan(config.log.type))
}
// CORS
app.use(cors({
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 204,
"maxAge": 3600
}));
// Routes
var indexRouter = require('./routes/index');
var authRouter = require('./routes/auth');
var messageRouter = require('./routes/message');
app.use('/', indexRouter);
app.use('/auth', authRouter);
app.use('/message', messageRouter);
app.listen(config.web.port || 8080);