-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
70 lines (64 loc) · 2.14 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
const express = require("express");
const session = require('express-session');
const path = require('path');
const morgan = require('morgan');
const nunjucks = require('nunjucks');
const dotenv = require('dotenv');
dotenv.config();
const indexRouter = require('./routes');
const authRouter = require('./routes/auth');
const exerciseRouter = require('./routes/exercises');
const variableRouter = require('./routes/variables');
const userRouter = require('./routes/users');
const userProfileRouter = require('./routes/userProfiles');
const recordRouter = require('./routes/records');
const fileRouter = require('./routes/files');
const dateRecordRouter = require('./routes/dateRecords');
const dietRouter = require('./routes/diets');
const { sequelize } = require('./models');
const app = express();
app.set('port', process.env.PORT || 5001);
app.set('view engine', 'html');
nunjucks.configure('views', {
express: app,
watch: true,
});
app.use(morgan('dev'));
app.use(express.urlencoded({ extended: false }));
app.use(express.json({limit: '10mb'}));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE');
res.header('Access-Control-Allow-Headers', 'content-type, bodycheck-access-token'); // JWT 로그인
next();
});
app.use(express.static(path.join(__dirname, 'public')));
sequelize.sync({ force: false })
.then(() => {
console.log('Database 연결 성공');
})
.catch((err) => {
console.error(err);
});
app.use(session({
resave: false,
saveUninitialized: false,
secret: process.env.COOKIE_SECRET,
cookie: {
httpOnly: true,
secure: false,
},
}));
app.use('/', indexRouter);
app.use('/auth', authRouter);
app.use('/exercises', exerciseRouter);
app.use('/variables', variableRouter);
app.use('/users', userRouter);
app.use('/userProfiles', userProfileRouter);
app.use('/records', recordRouter);
app.use('/files', fileRouter);
app.use('/dateRecords', dateRecordRouter);
app.use('/diets', dietRouter);
app.listen(app.get('port'), () => {
console.log(app.get('port'), '번 포트 활성화');
});