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

孤人 提交于 2019-12-05 15:07:52

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.

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
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!