-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
102 lines (79 loc) · 2.78 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// ---------------------/ 임포팅 /---------------------//
const express = require('express');
const rateLimit = require("express-rate-limit");
const session = require('express-session');
const path = require('path');
const os = require('os');
const app = express();
require("dotenv").config();
const port = 3000;
// 보안 설정
const helmet = require('helmet');
app.use(helmet({
contentSecurityPolicy: false
}));
app.use(helmet.xssFilter());
app.use(helmet.frameguard());
app.use(helmet.expectCt());
app.use(helmet.referrerPolicy());
app.use(helmet.ieNoOpen());
// views 파일 지정
app.set('views', path.join(__dirname, './src/views'));
app.use(express.static(path.join(__dirname, './src')));
// ejs 파일로 변환
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
app.use(express.json({limit: '50mb'}));
// ----------------------------------------------------//
// ---------------- 쿠키 및 레이트 리밋 ----------------//
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true
}));
app.use("/api/", rateLimit({
windowMs: 1 * 60 * 1000,
max: 200
})
);
app.use(rateLimit({
windowMs: 1 * 60 * 1000,
max: 300
})
);
// ----------------------------------------------------//
// -------------------- 라우팅 연결 --------------------//
var HomeRouter = require('./routes/home');
var LoginRouter = require('./routes/login');
var SignupRouter = require('./routes/signup');
var DashboardRouter = require('./routes/dashboard');
var MobileRouter = require('./routes/mobile');
var ServiceRouter = require('./routes/service');
app.use('/dashboard', DashboardRouter);
app.use('/mobile', MobileRouter);
app.use('/service', ServiceRouter);
app.use('/', HomeRouter);
app.use('/login', LoginRouter);
app.use('/signup', SignupRouter);
var APISignupRouter = require('./API/signup');
var APILoginRouter = require('./API/login');
var APILogoutRouter = require('./API/logout');
var APIWordsRouter = require('./API/words');
var APIClassRouter = require('./API/class');
app.use('/logout', APILogoutRouter);
/*------------------/ API /------------------*/
app.use('/api/signup', APISignupRouter);
app.use('/api/login', APILoginRouter);
app.use('/api/words', APIWordsRouter);
app.use('/api/class', APIClassRouter);
// ----------------------------------------------------//
// 에러 페이지 로드 404
app.use(function(req, res) {
res.render("404.html");
});
// ----------------------------------------------------//
app.listen(port, () => {
console.log(`App listening at http://${os.hostname}:${port}`);
console.log(`PID : ${process.pid}`);
});
// ----------------------------------------------------//