forked from sesac-ydp5-pullAmen/Dev_Conference_Info_Service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
74 lines (62 loc) · 1.96 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const express = require('express');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const nodemailer = require('nodemailer');
const config = require('./config/config.json');
const path = require('path');
const app = express();
const PORT = 8000;
const { sequelize } = require('./models');
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname + '/views/pages'));
app.use(cookieParser());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use('/static', express.static(__dirname + '/public'));
const MySessionSecretKey = config.sessionSecretKey;
// 세션 옵션 객체
app.use(
session({
secret: 'MySessionSecretKey',
resave: false,
saveUninitialized: true,
cookie: {
httpOnly: true,
maxAge: 3 * 60 * 60 * 1000, // 3시간
name: 'random-session-cookie-name',
},
})
);
// header session을 넣는 미들웨어
app.use((req, res, next) => {
res.locals.Id = 0;
res.locals.userId = '';
res.locals.userName = '';
res.locals.userIsManager = 0;
if (req.session.userInfo) {
const userInfo = req.session.userInfo;
res.locals.Id = userInfo.id;
res.locals.userId = userInfo.userId;
res.locals.userName = userInfo.userName;
res.locals.userIsManager = userInfo.userIsManager;
}
next();
});
const crawlingRouter = require('./routes/crawling');
app.use('/', crawlingRouter);
const mainRouter = require('./routes/main');
app.use('/', mainRouter);
const userRouter = require('./routes/user');
app.use('/', userRouter);
const conferenceRouter = require('./routes/conference');
app.use('/', conferenceRouter);
const reviewRouter = require('./routes/review');
app.use('/', reviewRouter);
app.get('*', (req, res) => {
res.render('404');
});
sequelize.sync({ force: false }).then(
app.listen(PORT, () => {
console.log(`http://localhost:${PORT} start `);
})
);