【问题标题】:Spring Boot CORS url top level domain/path not workingSpring Boot CORS url 顶级域/路径不起作用
【发布时间】:2018-05-26 10:09:17
【问题描述】:

使用以下代码测试 CORS (spring boot 1.7):

registry.addMapping("/**").allowedOrigins("http://example.com", "http://example.org");

如果我尝试使用http://example.com 之类的原始标头,它可以完美运行,当我使用指示端口(@98​​7654324@)、应用程序上下文(http://example.com/myApp)或路径(http://example.com/theSuperApp/get/catalogs)的 url 时,问题就来了,在任何其他情况下,它返回错误的不是确切的原始字符串,知道如何允许像下面这样的任何网址吗?:

https://example.org/
http://example.org:9080
http://example.org/aModule
http://example.org/aModule/submodule/subSubModule
http://example.org:80765/aModule/submodule/subSubModule

不用说我不想提供所有可能的 url 路径,因为随着时间的推移会添加新的路径

【问题讨论】:

    标签: spring-boot cors cross-domain


    【解决方案1】:

    当使用这样的声明性配置时,您必须添加所有可能的来源组合或使用"*" 来允许所有。

    来源包括协议方案、域和端口。

    【讨论】:

    • 1) 如果我想允许所有人,那么启用 CORS 将毫无意义。 2) 正如我所提到的,添加所有可能的值可能会很麻烦(现在和将来),特别是当我只想允许 2 个域具有任何应用程序上下文和路径时。
    猜你喜欢
    • 1970-01-01
    • 2021-11-10
    • 2017-03-03
    • 2019-10-30
    • 2021-06-07
    • 2013-07-06
    • 2019-10-25
    • 2021-07-31
    相关资源
    最近更新 更多