-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
61 lines (55 loc) · 1.74 KB
/
index.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
55
56
57
58
59
60
61
const express = require('express');
const cookieParser = require('cookie-parser');
const hpp = require('hpp');
const cors = require('cors');
const helmet = require('helmet');
const passport = require('passport');
const passportConfig = require('./config/passport')
const logger = require('./config/logger');
const sequelize = require('./models').sequelize;
const authRoutes = require('./controller/routes/auth');
const userRoutes = require('./controller/routes/user');
const challRoutes = require('./controller/routes/chall');
const noticeRoutes = require('./controller/routes/notice');
const logRoutes = require('./controller/routes/log');
const { corsOptions } = require('./config/secret.js');
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(passport.initialize());
app.use(hpp());
app.use(helmet());
app.use(cors({
origin: true,
credentials: true,
exposedHeaders: ['Content-Disposition']
}));
// app.use(cors(corsOptions));
passportConfig();
sequelize.sync();
// sequelize.sync({ force: true });
app.use('/', authRoutes);
app.use('/', userRoutes);
app.use('/', challRoutes);
app.use('/', noticeRoutes);
app.use('/', logRoutes);
app.use((req, res, next) => {
const err = new Error('404');
err.status = 404;
err.message = 'Not Found';
next(err);
})
app.use((err, req, res, next) => {
logger(req, 'error', `500 Server error. Error log: ${err}`, err);
res.status(err.status || 500).json({
success: false,
message: err.message || "Server error",
err
});
})
const server = app.listen('1288', () => {
const port = server.address().port;
const host = server.address().host;
console.log(`server listening on port ${port}`);
});