gateway 跨域

网上的写法,都有点不太一样。

首先,看一下我的gateway版本

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
            <version>3.0.3</version>
        </dependency>

配置文件:

spring:
  cloud:
    gateway:
      globalcors:
        cors-configurations:
          '[/**]':
            allowed-headers: "*"
            allowed-origins: "*"
            allowed-methods: "*"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Gateway服务中进行跨域配置有多种方法。一种方法是通过在网关的配置类中进行配置。具体的配置可以在yaml文件中查看,例如在org.springframework.cloud.gateway.config.GlobalCorsProperties类中配置。可以设置allowedOrigins来允许哪些网站的跨域请求,allowedMethods来允许的跨域ajax请求方式,allowedHeaders来允许在请求中携带的头信息,allowCredentials来确定是否允许携带cookie,maxAge来设置跨域检测的有效期。\[2\] 另一种方法是在Gateway服务的application.yml文件中进行配置。可以使用spring.cloud.gateway.globalcors来配置全局的跨域处理,设置allowedOrigins来允许哪些网站的跨域请求,allowedMethods来允许的跨域ajax请求方式,allowedHeaders来允许在请求中携带的头信息,allowCredentials来确定是否允许携带cookie,maxAge来设置跨域检测的有效期。\[3\] 总之,通过配置类或在application.yml文件中进行配置,可以实现Gateway服务的跨域配置。 #### 引用[.reference_title] - *1* *2* [Spring Cloud Gateway 解决跨域问题](https://blog.csdn.net/weixin_45481406/article/details/127573858)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Gateway网关-网关的cors跨域配置](https://blog.csdn.net/Leon_Jinhai_Sun/article/details/121186047)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值