【问题标题】:Change swagger host and port serving it statically更改 swagger 主机和静态服务它的端口
【发布时间】: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>

【问题讨论】:

    标签: json rest swagger


    【解决方案1】:
    1. 将host 添加为localhost:8081
    2. 删除basePath,basePath 用于更改主机后的相对路径,即如果您的Web 服务器托管在/v1/ 等,那么您可以使用basepath 来更改它

    我仍在尝试找出如何为生产、阶段、开发环境动态传递主机值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-20
      • 2011-10-11
      • 2013-03-27
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 2018-05-10
      相关资源
      最近更新 更多