-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (40 loc) · 1.17 KB
/
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
47
48
49
50
51
const express = require('express');
const path = require('path');
const cors = require('cors');
const logger = require('morgan');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
var sequelize = require('./models/index').sequelize;
const indexRouter = require('./routes/index');
const env = process.env.NODE_ENV || 'development';
const { config } = require('./server-config');
const app = express();
sequelize.sync();
app.use(
cors({
origin: config.SERVER_CONFIG_ORIGIN,
methods: config.SERVER_CONFIG_METHOD,
credentials: true
})
);
app.use(cookieParser());
app.use(
bodyParser.json({
verify(req, res, buf) {
req.rawBody = buf;
}
})
);
app.use(bodyParser.urlencoded({ extended: false }));
if (env === 'development') {
app.use(logger('dev'));
}
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.set('port', config.SERVER_PORT);
app.listen(config.SERVER_PORT, () =>
console.log(`Listening on port: ${config.SERVER_PORT}`)
);
module.exports = app;