【问题标题】:How to solve CORS issue in swagger-ui-express如何解决 swagger-ui-express 中的 CORS 问题
【发布时间】:2019-06-28 18:33:49
【问题描述】:

我收到“可能的跨域 (CORS) 问题?”运行此 swagger-ui-express 应用程序时 Spec2 出错:

const express = require('express');
var cors = require('cors');
const app = express();
const swaggerUi = require('swagger-ui-express');

var options = {
  explorer: true,
  swaggerOptions: {
    urls: [
      {
        url: 'http://petstore.swagger.io/v2/swagger.json',
        name: 'Spec1'
      },
      {
        url: 'http://xxx.xxx.xxx.xxx:xxxxx/swagger.json',
        name: 'Spec2'
      }
    ]
  }
}

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(null, options));

app.listen(8080, () => console.log(`Listening on port 8080!`))

app.use(cors())app.use(swaggerUi.cors()) 都没有帮助。怎么解决?

【问题讨论】:

标签: javascript node.js express swagger-ui


【解决方案1】:

检查link,它提供了解决问题的方法。另外,如果你愿意,你可以在 chrome 中安装 CORS 插件并尝试一下。

【讨论】:

  • 谢谢 Arun.. 我看到了,但不知道如何将它与我的选项对象而不是 yaml 文件一起使用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-02
  • 2021-09-06
  • 2016-11-24
  • 2021-01-28
  • 2019-12-07
  • 2021-02-17
相关资源
最近更新 更多