Question

The api-docs was working fine earlier. It stopped working and now I get

Can't read swagger JSON from http://localhost:9000/api-docs/

If I change src/main/webapp/swagger-ui/index.html

var apiUrl = "http://localhost:8080/swagger-ui/index.html";

I get "Can't read from server. It may not have the appropriate access-control-origin settings."

Was it helpful?

Solution 2

See Jerome's fix on https://github.com/jhipster/generator-jhipster/issues/277 by changing gruntfile.js to include below lines in connect/proxies section

,{
context: '/api-docs',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
}

OTHER TIPS

I ran into the same problem and found out the the generated classes have the package com.mycompany.myapp.config.apidoc but they actually are under com.mycompany.myapp.apidoc.

You can solve this by moving the java files to the correct package com.mycompany.myapp.config.apidoc.

You have to enable CORS for that sake just add these 3 res.header lines into your API then CORS will be enabled when your accessing that API so that you will not get error like access-control-origin settings.

app.get('/swaggerJson', function(req, res){  
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
  res.header("Access-Control-Allow-Methods", "GET, PUT, POST, OPTIONS");      
  res.json(swaggerJSON);
});

Hope this will help you..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top