문제

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."

도움이 되었습니까?

해결책 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
}

다른 팁

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..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top