37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
window.ui = SwaggerUIBundle({
|
|
url: "/docs/api-docs.json",
|
|
dom_id: '#swagger-ui',
|
|
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
|
|
layout: "StandaloneLayout",
|
|
onComplete: function() {
|
|
// 로그인 요청 후 자동 Authorize 처리
|
|
window.ui.getSystem().events.on('response', function(res) {
|
|
const path = res.request.url;
|
|
const method = res.request.method;
|
|
|
|
if (path.includes('/api/login') && method === 'post' && res.status === 200) {
|
|
const token = res.body.token;
|
|
|
|
// 🔐 자동 Authorize
|
|
window.ui.authActions.authorize({
|
|
ApiKeyAuth: {
|
|
name: "X-API-KEY",
|
|
schema: {
|
|
type: "apiKey",
|
|
in: "header",
|
|
name: "X-API-KEY"
|
|
},
|
|
value: token
|
|
}
|
|
});
|
|
}
|
|
|
|
if (path.includes('/api/logout') && res.status === 200) {
|
|
// 🔓 자동 Logout
|
|
window.ui.authActions.logout();
|
|
}
|
|
|
|
});
|
|
}
|
|
});
|