-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (51 loc) · 1.77 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
import express from 'express';
import {tempRouter} from "./src/routes/temp.route.js";
import { specs } from './config/swagger.config.js';
import SwaggerUi from 'swagger-ui-express';
import cartRouter from "./src/routes/cart.route.js";
import storeRouter from './src/routes/store.route.js';
import bookmarkRouter from './src/routes/bookmark.route.js';
import dotenv from "dotenv";
import cors from "cors";
import userRouter from "./src/routes/user.route.js";
dotenv.config()
const app = express();
const port = 3000;
// server setting - veiw, static, body-parser etc..
app.set('port', process.env.PORT || 3000) // 서버 포트 지정
app.use(cors()); // cors 방식 허용
app.use(express.static('public')); // 정적 파일 접근
app.use(express.json()); // request의 본문을 json으로 해석할 수 있도록 함 (JSON 형태의 요청 body를 파싱하기 위함)
app.use(express.urlencoded({extended: false}));
const myLogger = (req, res, next) => {
console.log("LOGGED");
next();
}
// swagger
app.use('/api-docs', SwaggerUi.serve, SwaggerUi.setup(specs));
app.use(myLogger);
app.get('/', (req, res) => {
console.log("/");
res.send('PackIt 루트페이지 테스트중(2)');
});
app.get('/hello', (req, res) => {
console.log("/hello");
res.send('패킷 랜딩 페이지');
});
// 로그인
app.use('/auth', userRouter);
// 가게 정보
app.use('/order', storeRouter);
app.use('/temp', tempRouter);
//장바구니
app.use('/cart',cartRouter);
//북마크
app.use('/bookmark',bookmarkRouter)
// error handling
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(500).send(err.stack);
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});