Getting No-Access-Control-Allow-Origin with Swagger Server and Foreman Rails

My server is now running on 0.0.0.0/10100. When I try to access my Swagger docs, I get the following error in the console:

XMLHttpRequest cannot load http://0.0.0.0/api/v1/types.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://0.0.0.0:5100' is therefore not allowed access. 

I wonder why this is happening. Here is my Swagger configuration in index.html:

$(function () {
      window.swaggerUi = new SwaggerUi({
      url: "/api-docs.json",
      dom_id: "swagger-ui-container",
      supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
      onComplete: function(swaggerApi, swaggerUi){
        log("Loaded SwaggerUI");

        if(typeof initOAuth == "function") {
          /*
          initOAuth({
            clientId: "your-client-id",
            realm: "your-realms",
            appName: "your-app-name"
          });
          */
        }
        $('pre code').each(function(i, e) {
          hljs.highlightBlock(e)
        });
      },
      onFailure: function(data) {
        log("Unable to Load SwaggerUI");
      },
      docExpansion: "none"
    });
+4
source share
2 answers

Is CORS support enabled for your web service? The Swagger documentation states that CORS support is required to work. The error message you receive is the same message that I received from my Grails project before I added CORS support.

+4
source

---: * Chrome-, .

. , , , youtube enable.

0

Source: https://habr.com/ru/post/1539681/


All Articles