Unable to read swagger JSON from http: // localhost: 9000 / api-docs /

Previously, api-docs worked fine. He 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 "I can’t read from the server. Perhaps it does not have the appropriate access control source settings."

+4
source share
3 answers

See Jerome's fix at https://github.com/jhipster/generator-jhipster/issues/277 by modifying the gruntfile.js file to include below line in connect / proxies section

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

, com.mycompany.myapp.config.apidoc, com.mycompany.myapp.apidoc.

, java com.mycompany.myapp.config.apidoc.

0

You have to enable CORS for this, just add these 3 lines of res.header to your API, then CORS will be included when you get access to this API so that you don't get an error like access control source 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);
});
Run codeHide result

Hope this helps you.

0
source

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


All Articles