File tree Expand file tree Collapse file tree 4 files changed +82
-2
lines changed
Expand file tree Collapse file tree 4 files changed +82
-2
lines changed Original file line number Diff line number Diff 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 : {
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import paymentRouter from "./payment/payment.routes.js"
1010import pointRouter from "./point/point.routes.js"
1111import requestRouter from "./request/request.routes.js"
1212import homeRouter from "./home/home.routes.js"
13+ import tokenRouter from "./token.routes.js"
1314
1415const router = express . Router ( ) ;
1516
@@ -24,6 +25,7 @@ router.use("/payments", paymentRouter);
2425router . use ( "/points" , pointRouter ) ;
2526router . use ( "/requests" , requestRouter ) ;
2627router . use ( "/home" , homeRouter ) ;
28+ router . use ( "/" , tokenRouter ) ;
2729
2830
2931export default router ;
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments