带有远程Swagger-UI / CORS错误的Micronaut [英] Micronaut with remote Swagger-UI / CORS error

查看:462
本文介绍了带有远程Swagger-UI / CORS错误的Micronaut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在努力使用Micronaut 1.2.5和远程Swagger-UI。我的想法是在一个Swagger-UI实例中收集多个API。

At the moment I'm struggling with Micronaut 1.2.5 and a remote Swagger-UI. My idea is to collect several APIs in one Swagger-UI instance.

在我的Micronaut项目中,我能够创建有效的Swagger YAML文件,并使用此解决方案用maven的Micronaut挥杆工具(在我的项目中提供静态Swagger-UI页面),一切正常。

In my Micronaut project I'm able to create a valid Swagger YAML file and with this solution Swagger for Micronaut with maven (serve static Swagger-UI page in my project) everything works fine.

要让Micronaut与位于我服务之外的其他域中的远程Swagger-UI一起使用,我在application.yml中进行了以下设置:

To let Micronaut work with a remote Swagger-UI which resides in another domain than my service I did the following settings in application.yml:

micronaut:
  server:
    cors:
      endabled: true
      configurations:
        web:
          exposedHeaders:
            - Access-Control-Allow-Origin
            - Access-Control-Allow-Headers
            - Access-Control-Allow-Methods

不幸的是,这无济于事,Swagger-UI失败,

Unfortunately, this does not help, Swagger-UI fails with

Fetch error
NetworkError when attempting to fetch resource. https://....yml

Fetch error
Possible cross-origin (CORS) issue? The URL origin (https://aa) does not match the page (https://bb). Check the server returns the correct 'Access-Control-Allow-*' headers.

在Micronaut响应中,不包含Access-Control-Allow标头。虽然似乎没有调用调试CorsFilter,但是doFilter方法中的断点没有任何作用。

In the Micronaut response, no Access-Control-Allow headers are contained. While debugging CorsFilter seems not to be called, the breakpoint in the doFilter method has no effect.

有什么想法吗?

预先感谢您,
Christoph

Thank you in advance, Christoph

推荐答案

经过一番调查,我能够解决问题。

After some investigation I was able to solve the problems.

我的application.yaml现在看起来像这样:

My application.yaml looks now like this:

micronaut:
  server:
    cors:
      enabled: true
      configurations:
        web:
          exposedHeaders:
            - Content-Type
            - Authorization
            - '*'

与Chrome和Edge有关的问题是由自签名SSL证书引起的,

The issues regarding Chrome and Edge were caused by self signed SSL certificates, which were not accepted.

要解决该问题,这有助于在浏览器中打开swagger.yml文件并将自签名SSL证书添加到浏览器。之后,您就可以在Swagger中使用Micronaut API。

To solve that it helps to open the swagger.yml file in your browser and add the self signed SSL certificate to your browser. After that you are able to use your Micronaut API in Swagger.

这篇关于带有远程Swagger-UI / CORS错误的Micronaut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆