-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (46 loc) · 1.36 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
49
50
51
52
53
54
55
56
const cors = require('cors');
const express = require('express');
const session = require('express-session');
const passport = require('passport');
const SequelizeStore = require('connect-session-sequelize')(session.Store);
const db = require('./src/models/');
const userRouter = require('./src/routes/user');
const productRouter = require('./src/routes/product');
const reviewRouter = require('./src/routes/review');
const orderRouter = require('./src/routes/order');
const notFound = require('./src/middlewares/not-found');
const errHandler = require('./src/middlewares/err-handler');
const app = express();
const sessionStore = new SequelizeStore({
db: db.sequelize,
table: 'session'
});
app.use(session({
secret: process.env.SESSION_SECRET,
store: sessionStore,
resave: false,
saveUninitialized: false,
cookies: {
secure: false,
httpOnly: true,
maxAge: 7 * 24 * 60 * 60 * 1000 // expires in 7 days
}
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.json({
verify: (req, res, rawBody) => {
req.rawBody = rawBody;
}
}));
app.use(cors({
origin: process.env.ALLOWED_ORIGIN
}));
app.use(express.static('media'));
app.use('/users', userRouter);
app.use('/products', productRouter);
app.use('/reviews', reviewRouter);
app.use('/orders', orderRouter);
app.use(notFound);
app.use(errHandler);
module.exports = app;