-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (62 loc) · 2.03 KB
/
index.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
const express = require('express');
const mysql = require('mysql2/promise');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');
const app = express();
const cors = require('cors');
require('dotenv').config();
const port = process.env.PORT;
app.use(cors());
app.use(express.json());
// db 관련 설정
const db = require('./models');
db.sequelize
.sync({force: false})
.then(() => {
console.log('DB 연결 성공');
})
.catch(err => console.log(err));
// 쿠키, 세션 설정
app.use(cookieParser(process.env.COOKIE_SECRET));
app.use(session({
secret: process.env.COOKIE_SECRET,
resave: false,
saveUninitialized: false,
}));
// 로그인을 위한 Passport 세팅
const passportConfig = require('./passport');
passportConfig();
app.use(passport.initialize());
app.use(passport.session());
app.get('/', (req, res) => {
res.send('Hello World!');
});
// 로그인 인증 토큰 발급용 >> 수정 가능성 o
app.get('/token', (req, res) => {
res.json(req.query);
})
// 라우트 설정
const authRouter = require('./routes/auth');
app.use('/auth', authRouter);
const reviewRouter = require('./routes/reviewRoutes');
app.use('/api/review', reviewRouter);
const userRouter = require('./routes/userRoutes');
app.use('/api/user', userRouter);
const mapRouter = require('./routes/mapRouters');
app.use('/api/map', mapRouter);
const photoRouter = require('./routes/photoRouter');
app.use('/api/photo', photoRouter);
const boothLikeRouter = require('./routes/boothLikeRouter');
app.use('/api/booth', boothLikeRouter);
const albumRouter = require('./routes/albumRouter');
app.use('/api/album', albumRouter);
// 스웨거 세팅
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const path = require('path');
const swaggerSpec = YAML.load(path.join(__dirname, './build/swagger.yaml'));
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});