-1

我正在 localhost:3000 上开发一个 REACT 应用程序,并在 localhost:8080 上运行一个 Spring Data Rest 后端。我发现了如何禁用特定 RestRepositories 的 CORS 策略,例如:

@CrossOrigin("*")
public interface EmployeeRepository extends PagingAndSortingRepository<Employee, Long> {
}

现在可以访问以下 URL:localhost:8080/api/employees

但是,我正在尝试对基本路径 url 本身执行 GET 请求:localhost:8080/api。这仍然被 CORS 策略阻止。我想禁用该 URL 上的 CORS 策略。

在此处输入图像描述

我找到了以下文档:https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.configuring-cors这适用于存储库本身,但没有结果在基本 URL 上。

任何想法都非常感谢。

4

1 回答 1

-1

如果您使用 create-react-app 创建了 react 应用程序,请将以下内容添加到 package.json:

"proxy":"http://localhost:8080",

这会将您的所有请求代理到后端服务器。这仅用于开发。

于 2020-10-17T10:59:04.877 回答