gpt4 book ai didi

java - Jhipster CORS 启用

转载 作者:行者123 更新时间:2023-11-30 06:03:40 28 4
gpt4 key购买 nike

我正在使用 Jhipster 生成 API。

我的 api 已经启动了,我们可以调用它:

https://api.staging.test.com/

我的 FE 应用程序已打开:

https://staging.test.com/

这是我在 application-prod.yml 中启用 Cors 的配置

cors:
allowed-origins: "https://staging.test.com/"
allowed-methods: "*"
allowed-headers: GET, PUT, POST, DELETE, OPTIONS
exposed-headers: "Authorization,Link,X-Total-Count"
allow-credentials: true
max-age: 1800

我仍然得到这个错误:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://staging.test.com' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

在 Spring boot 中是否需要做更多的事情来启用 CORS?

最佳答案

在 JHipster 的 Prod 模式下启用 CORS 所需的唯一配置是设置 jhipster.cors 配置,如下所示。需要注意的一件事是,如果您的前端正在使用端口,则需要将其包含在 allowed-origins 键中。

jhipster:
cors:
allowed-origins: "https://staging.test.com:8080"
allowed-methods: "*"
allowed-headers: "*"
exposed-headers: "Authorization,Link,X-Total-Count"
allow-credentials: true
max-age: 1800

这由 JHipsterProperties 加载并在 WebConfigurer.java 中使用应用 CORS 配置。

关于java - Jhipster CORS 启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51730409/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com