简体   繁体   English

在swagger-ui-express中如何解决CORS问题

[英]How to solve CORS issue in swagger-ui-express

I'm getting "Possible cross-origin (CORS) issue?" 我收到“可能的跨域(CORS)问题?” error for Spec2 when run this swagger-ui-express app: 运行此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!`))

Neither app.use(cors()) nor app.use(swaggerUi.cors()) helps. app.use(cors())app.use(swaggerUi.cors())帮助。 How can it be fixed? 如何解决?

check the link which gives the way to overcome the issue. 检查提供克服问题方法的链接 Also, you can install CORS plugin in chrome if you want and try it. 此外,如果需要,您可以在chrome中安装CORS插件,然后尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM