From b6c76a7bcd2ca90b1ab0480f7b85ae45f5e37815 Mon Sep 17 00:00:00 2001 From: weejee12 Date: Thu, 31 Jul 2025 22:21:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=ED=86=A0=ED=81=B0=20=EB=B0=9C=EA=B8=89=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/swagger/token.json | 33 ++++++++++++++++++++++++++++ src/routes.js | 2 ++ src/token.routes.js | 41 +++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/common/swagger/token.json create mode 100644 src/token.routes.js diff --git a/src/common/swagger/token.json b/src/common/swagger/token.json new file mode 100644 index 0000000..f5ebd70 --- /dev/null +++ b/src/common/swagger/token.json @@ -0,0 +1,33 @@ +{ + "paths": { + "/api/token": { + "get": { + "tags": ["Token"], + "summary": "테스트용 임시 토큰 발급", + "description": "userId 1번 회원의 JWT 토큰을 발급합니다.", + "responses": { + "200": { + "description": "토큰 발급 성공", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "token": { + "type": "string", + "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsIm5pY2tuYW1lIjoi7YWM7Iqk7Yq466mEIiwiYWNjb3VudElkIjoxLCJwcm92aWRlciI6Imdvb2dsZSIsImlhdCI6MTY5MTY3MjA5NCwiZXhwIjoxNjkxNjcyNjk0fQ.abc123def456" + }, + "userId": { + "type": "integer", + "example": 1 + } + } + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/routes.js b/src/routes.js index 9759750..6840840 100644 --- a/src/routes.js +++ b/src/routes.js @@ -10,6 +10,7 @@ import paymentRouter from "./payment/payment.routes.js" import pointRouter from "./point/point.routes.js" import requestRouter from "./request/request.routes.js" import homeRouter from "./home/home.routes.js" +import tokenRouter from "./token.routes.js" const router = express.Router(); @@ -24,6 +25,7 @@ router.use("/payments", paymentRouter); router.use("/points", pointRouter); router.use("/requests", requestRouter); router.use("/home", homeRouter); +router.use("/", tokenRouter); export default router; \ No newline at end of file diff --git a/src/token.routes.js b/src/token.routes.js new file mode 100644 index 0000000..d951b69 --- /dev/null +++ b/src/token.routes.js @@ -0,0 +1,41 @@ +import { Router } from 'express'; +import { PrismaClient } from '@prisma/client'; +import { signJwt } from './jwt.config.js'; +import { StatusCodes } from 'http-status-codes'; +import { parseWithBigInt, stringifyWithBigInt } from './bigintJson.js'; + +const router = Router(); +const prisma = new PrismaClient(); + +router.get('/token', async (req, res, next) => { + try { + const user = await prisma.user.findUnique({ + where: { id: 1 }, + include: { + account: true + } + }); + + const payload = { + userId: user.id.toString(), + nickname: user.nickname, + accountId: user.accountId.toString(), + provider: user.account.provider + }; + + const token = signJwt(payload); + + const result = { + token, + userId: user.id + }; + + const responseData = parseWithBigInt(stringifyWithBigInt(result)); + + res.status(StatusCodes.OK).success(responseData); + } catch (err) { + next(err); + } +}); + +export default router; From af27c595a0060be9308f75e346f7b8bd4b50a614 Mon Sep 17 00:00:00 2001 From: weejee12 Date: Thu, 31 Jul 2025 22:26:55 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EC=A3=BC=EC=86=8C=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=84=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/swagger/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/swagger/index.js b/src/common/swagger/index.js index 49d12df..9f51e47 100644 --- a/src/common/swagger/index.js +++ b/src/common/swagger/index.js @@ -34,8 +34,12 @@ const swaggerDefinition = { }, servers: [ { - url: 'http://localhost:3000', - description: 'Development server', + url: process.env.NODE_ENV === 'production' + ? 'http://3.35.0.31:3000' + : 'http://localhost:3000', + description: process.env.NODE_ENV === 'production' + ? 'Production server' + : 'Development server', }, ], components: {