【发布时间】:2021-02-23 12:24:08
【问题描述】:
受this sample repository, 的启发,我正在使用protoc 生成一个大摇大摆的json 输出并提供服务。但是,由于某些原因,我将 swagger 内容托管在与我的 REST api 服务 (:8000) 不同的端口 (:10000) 上。
我正在使用 Go 库 statik 来捆绑 swagger 资产并为它们提供服务。它可以工作,并且在转到localhost:10000时会提供一个网页。
然而,每一个cURL 招摇的请求似乎都仅限于localhost:10000。 REST API 位于 localhost:8081。
使用静态内容提供 swagger-ui,如何更改 REST api 服务器的主机/端口?
我尝试进入 swagger-ui 内容的index.html 以在此处添加basePath,但没有运气。每个请求仍然发送给:10000
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "./service.swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
// I added this, but it did not change anything.
basePath: "localhost:8081"
})
// End Swagger UI call region
window.ui = ui}
</script>
【问题讨论】: