可以将Swagger UI部署到网关的同一个服务器上,并通过网关转发到Swagger UI,让用户能够通过网关访问。需要注意的是,在转发请求时需要将相应的路径修改为Swagger UI路径。
以下是一个Kong网关的代码示例,将Swagger UI部署到了同一个服务器上,并且转发的路径为/api-docs:
server {
listen 80;
server_name your-domain.com;
location /api-docs {
proxy_pass http://localhost:8080/api-docs;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
# Your Kong configuration
kong_...
# Enable the Swagger UI plugin
kong_plugins = bundled, swagger-ui
# Configure the Swagger UI plugin
plugins = bundled, swagger-ui@0.4.0
plugins.swagger-ui.config.api_url = "/api-docs"
}
}