Swagger UI - “ TypeError: Failed to fetch” on valid response

后端 未结 9 1449
一生所求
一生所求 2020-12-14 02:27

I\'ve just pulled down the latest Swagger from the Git repo (3.0.19) using: https://github.com/swagger-api/swagger-ui.git and updated my API to use the new version.

9条回答
  •  失恋的感觉
    2020-12-14 03:01

    Because the problem of cross-origin means your website is hosted on either locally or with port 8000 or different port, and your swagger's port number is different, so this problem is genuine. We can fix it by giving permission.

    Here is the node code:

    app.use( (request, response, next) => {
        response.header("Access-Control-Allow-Origin", "*");
        response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
        next();
    });
    

    We can solve by using CORS npm as well. https://www.npmjs.com/package/cors

提交回复
热议问题