swagger - nginx 代理背后的 SpringDoc/Swagger
问题描述
我们在代理后面运行服务,nginx
以便:
http://service-post:8080/swagger-ui.html
被路由到公共地址https://host.com/services/post/swagger-ui.html
或者从另一种方式定义:
当 nginx 收到 on 请求时https://host.com/services/post/swagger-ui.html
,它会剥离/services/post/
前缀并将请求传递给路径上的post
服务。/swagger-ui.html
在设置任何东西(使用默认 SpringDoc 配置)之前,我可以正确地看到http://service-post:8080/swagger-ui.html
.
要在 host.com 上设置公共地址的路径,我使用:
springdoc.api-docs.path: /services/post/api-docs
springdoc.swagger-ui.path: /services/post/swagger-ui.html
springdoc.swagger-ui.configUrl: /services/post/v3/api-docs/swagger-config
然而,这似乎完全阻止了它:
/swagger-ui.html
,/api-docs
并/v3/api-docs/swagger-config
返回404
forservice-post:8080/*
和https://host.com/services/post/*
似乎唯一可行的是https://host.com/services/post/swagger-ui/index.html,它显示了 petstore 文档。
我们没有使用 Spring Boot ,只使用5.3.1版本的 Spring MVC 。
那么如何设置以保持对原始路径(例如/api-docs
)的处理,但在前缀路径()上执行查找/services/post/api-docs
?
解决方案
最后我完全忽略了默认重定向:
swagger-ui.html
-> `swagger-ui/index.html?url=/v3/api-docs
并实现了我自己的:
docs
->swagger-ui/index.html?url=MY_PREFIX/v3/api-docs
这样我就不需要更改任何东西,一切都使用默认设置。
推荐阅读
- android - 如何将字符串从片段发送到类以更改 kotlin 中的 Json API?
- kotlin - 在 Kotlin 上限制用户输入
- json - 运行以下代码时出现错误:
- uipath - 提取数据时,UiPath 选择器在 Google Chrome 警报消息框中不起作用
- ios - 删除按钮和行之间不需要的空间 swift xcode
- autodesk-forge - 如何在 Autodesk Forge 查看器中将点击事件添加到图钉?
- python - Python:将不规则离散时间观察转换为规则时间序列
- python-3.x - 在网络中旋转 k 部图
- java - 适用于 Lambda 的 AWS 开发工具包 V2 Maven 库是什么?
- mongodb - MongoDB中的索引?