-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
84 lines (74 loc) · 2.56 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
75
76
77
78
79
80
81
82
83
84
const fs = require('fs');
//const helmet = require('helmet');
const path = require('path');
const express = require('express')
const session = require('express-session')
const bodyParser = require('body-parser');
const FileStore = require('session-file-store')(session)
var authRouter = require('./src/routes/auth.js');
var authCheck = require('./src/utils/authCheck.js');
var IpCheck = require('./src/utils/IpCheck.js');
var exception = require('./src/utils/exception.js');
var articlesRouter = require('./src/routes/articles.js');
var commentsRouter = require('./src/routes/comments.js');
var rouletteRouter = require('./src/routes/roulette.js');
var articlesRouter = require('./src/routes/articles');
var commentsRouter = require('./src/routes/comments');
var adminRouter = require('./src/routes/admin');
const app = express();
const port = 80;
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ limit: '5mb' }))
app.use(session({
secure: true,
secret: process.env.SESSION_SECRET_KEY,
resave: true,
saveUninitialized: true,
store: new FileStore(),
cookie: { //세션 쿠키 설정 (세션 관리 시 클라이언트에 보내는 쿠키)
httpOnly: true, // 자바스크립트를 통해 세션 쿠키를 사용할 수 없도록 함
secure: false,
maxAge: 60000000
}
}))
app.use((req, res, next) => {
req.session.clientIP = req.ip; // 클라이언트의 IP 주소 저장
next();
});
//app.use(helmet());
app.use('/uploads', express.static(__dirname + '/uploads'));
app.get('/', (req, res) => {
if (!authCheck.isLogined(req, res)) {
res.redirect('/auth/login');
return;
} else if (!IpCheck.isSameIP(req, res)){
res.send(exception.alertWindow("잘못된 접근입니다.", "/auth/logout"));
return;
} else {
res.redirect('/main');
return;
}
})
// Routers
app.use('/auth', authRouter);
app.use('/articles', articlesRouter);
app.use('/comments', commentsRouter);
app.use('/roulette', rouletteRouter);
app.use('/admin', adminRouter);
app.get('/main', (req, res) => {
if (!authCheck.isLogined(req, res)) {
res.redirect('/auth/login');
return;
} else if (!IpCheck.isSameIP(req, res)){
res.send(exception.alertWindow("잘못된 접근입니다.", "/auth/logout"));
return;
}
const filePath = path.join(__dirname, './src/templates/main.html');
fs.readFile(filePath, 'utf8', function (err, html) {
res.send(html);
});
})
// listen carefully
app.listen(port, () => {
console.log(`Node.js app listening on port ${port}`)
})