forked from livingalone-2023/livingalone-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (45 loc) · 1.48 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
const express = require('express');
const session = require('express-session');
const cors = require('cors');
const multer = require('multer');
const sequelize = require("./config/config");
//const sequelize = require("./models");
const path = require('path');
const bodyParse = require('body-parser')
const app = express();
const port = 3000;
// routes
const userRouter = require('./routes/user')
const answerRouter = require('./routes/answer')
const questionRouter = require('./routes/question')
// app.get('/', (req, res) => {
// return res.send("홀로서기");
// })
sequelize.sync() // 이 옵션은 테이블 구조를 현재 모델 정의와 맞도록 변경합니다.
.then(() => {
console.log('Database & tables created/updated!');
// 서버 시작
app.listen(port, () => {
console.log(port, '번 포트에서 대기 중');
});
})
.catch((error) => {
console.error('Unable to sync database:', error);
});
// 미들웨어
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(require('cookie-parser')());
app.use(bodyParse.json())
app.use(session({
secret: 'your-secret-key',
resave: false,
saveUninitialized: true,
}));
// router - 진입할 엔드포인트 + 진입할 라우터
app.use('/users', userRouter)
app.use('/questions', questionRouter)
app.use('/answers', answerRouter)
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));