Skip to content

Commit 855e2ed

Browse files
authored
Merge pull request #102 from umc-commit/feat/set-swagger
[FEAT] 스웨거 서버 환경별 설정 및 테스트용 토큰 API 추가
2 parents 848f723 + af27c59 commit 855e2ed

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

src/common/swagger/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ const swaggerDefinition = {
3434
},
3535
servers: [
3636
{
37-
url: 'http://localhost:3000',
38-
description: 'Development server',
37+
url: process.env.NODE_ENV === 'production'
38+
? 'http://3.35.0.31:3000'
39+
: 'http://localhost:3000',
40+
description: process.env.NODE_ENV === 'production'
41+
? 'Production server'
42+
: 'Development server',
3943
},
4044
],
4145
components: {

src/common/swagger/token.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"paths": {
3+
"/api/token": {
4+
"get": {
5+
"tags": ["Token"],
6+
"summary": "테스트용 임시 토큰 발급",
7+
"description": "userId 1번 회원의 JWT 토큰을 발급합니다.",
8+
"responses": {
9+
"200": {
10+
"description": "토큰 발급 성공",
11+
"content": {
12+
"application/json": {
13+
"schema": {
14+
"type": "object",
15+
"properties": {
16+
"token": {
17+
"type": "string",
18+
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsIm5pY2tuYW1lIjoi7YWM7Iqk7Yq466mEIiwiYWNjb3VudElkIjoxLCJwcm92aWRlciI6Imdvb2dsZSIsImlhdCI6MTY5MTY3MjA5NCwiZXhwIjoxNjkxNjcyNjk0fQ.abc123def456"
19+
},
20+
"userId": {
21+
"type": "integer",
22+
"example": 1
23+
}
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}

src/routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import paymentRouter from "./payment/payment.routes.js"
1010
import pointRouter from "./point/point.routes.js"
1111
import requestRouter from "./request/request.routes.js"
1212
import homeRouter from "./home/home.routes.js"
13+
import tokenRouter from "./token.routes.js"
1314

1415
const router = express.Router();
1516

@@ -24,6 +25,7 @@ router.use("/payments", paymentRouter);
2425
router.use("/points", pointRouter);
2526
router.use("/requests", requestRouter);
2627
router.use("/home", homeRouter);
28+
router.use("/", tokenRouter);
2729

2830

2931
export default router;

src/token.routes.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Router } from 'express';
2+
import { PrismaClient } from '@prisma/client';
3+
import { signJwt } from './jwt.config.js';
4+
import { StatusCodes } from 'http-status-codes';
5+
import { parseWithBigInt, stringifyWithBigInt } from './bigintJson.js';
6+
7+
const router = Router();
8+
const prisma = new PrismaClient();
9+
10+
router.get('/token', async (req, res, next) => {
11+
try {
12+
const user = await prisma.user.findUnique({
13+
where: { id: 1 },
14+
include: {
15+
account: true
16+
}
17+
});
18+
19+
const payload = {
20+
userId: user.id.toString(),
21+
nickname: user.nickname,
22+
accountId: user.accountId.toString(),
23+
provider: user.account.provider
24+
};
25+
26+
const token = signJwt(payload);
27+
28+
const result = {
29+
token,
30+
userId: user.id
31+
};
32+
33+
const responseData = parseWithBigInt(stringifyWithBigInt(result));
34+
35+
res.status(StatusCodes.OK).success(responseData);
36+
} catch (err) {
37+
next(err);
38+
}
39+
});
40+
41+
export default router;

0 commit comments

Comments
 (0)