-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
73 lines (58 loc) · 1.86 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
62
63
64
65
66
67
68
69
70
71
72
73
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')
// configs
const secret = require('./config/secret');
const passportConfig = require('./config/passport');
const app = express();
// import sequelize models
const {sequelize} = require('./models');
const UserRoutes = require('./routes/UserRoutes');
const BookRoutes = require('./routes/BookRoutes');
const RentalRoutes = require('./routes/RentalRoutes');
// const LoginRoutes = require('./routes/LoginRoutes');
const AuthRoutes = require('./routes/AuthRoutes');
const FileRoutes = require('./routes/FileRoutes');
const ProjectRoutes = require('./routes/ProjectRoutes');
const NotificationRoutes = require('./routes/NotificationRoutes');
// use middlewares
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(hpp());
app.use(helmet());
app.use(cors(secret.corsOptions));
app.use(passport.initialize());
passportConfig();
// routes
app.use('/user', UserRoutes);
app.use('/book', BookRoutes);
app.use('/rental', RentalRoutes);
// app.use('/login', LoginRoutes);
app.use('/auth', AuthRoutes);
app.use('/file', FileRoutes);
app.use('/project', ProjectRoutes);
app.use('/notification', NotificationRoutes);
// error handler
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) => {
res.status(err.status || 500).json({
success: false,
message: err.message || "Server error occurred",
err
});
});
sequelize.sync();
const server = app.listen('7908', () => {
const address = server.address();
const {port} = address;
console.log(`server listening on port ${port}`);
});