Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nginx에서 swagger/swagger-v2/ 경로 허용 #640

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ passport.use('jwt', JwtStrategy);

// Swagger 연결
const specs = swaggerJsdoc(swaggerOptions);
app.get('/swagger.json', (_req, res) => res.json(specs));
const v1JsonPath = '/swagger/openapi.json';
app.get(v1JsonPath, (_req, res) => res.json(specs));
app.use(
'/swagger',
swaggerUi.serveFiles(undefined, { swaggerUrl: '/swagger.json' }),
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: '/swagger.json' }),
swaggerUi.serveFiles(undefined, { swaggerUrl: v1JsonPath }),
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: v1JsonPath }),
);

const v2Specs = generateOpenApi(
Expand All @@ -64,11 +65,13 @@ const v2Specs = generateOpenApi(
setOperationId: false,
},
);
app.get('/docs.json', (_req, res) => res.json(v2Specs));

const v2JsonPath = '/swagger-v2/openapi.json';
app.get(v2JsonPath, (_req, res) => res.json(v2Specs));
app.use(
'/docs',
swaggerUi.serveFiles(undefined, { swaggerUrl: '/docs.json' }),
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: '/docs.json' }),
'/swagger-v2',
swaggerUi.serveFiles(undefined, { swaggerUrl: v2JsonPath }),
swaggerUi.setup(undefined, { explorer: true, swaggerUrl: v2JsonPath }),
);

// dev route
Expand Down
9 changes: 9 additions & 0 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /swagger-v2/ {
auth_basic "Admin page (V2)";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
proxy_pass http://backend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

#error_page 404 /404.html;

Expand Down