Gateway网关跨域问题

一、模拟跨域问题

通过vscode打开,模拟跨域问题的前端资料,在黑马视频中老师那个命令我似乎是不行的,应该是还没下载相关操作指令,但是可以通过下载一个插件来实现启动(Live Server)。

下载好后右键,选择open with live server启动。

启动成功后会有端口提示。

复制端口,在浏览器打开http://localhost:5500/ ,通过打开检查,看控制器可以看到有跨域问题,这里我已经解决跨域问题,在之后java项目中配置后才会出现。

二、解决跨域问题

将以下yml配置写入项目的配置文件中,重新启动,即可解决跨域问题

复制代码
spring:
  cloud:
    gateway:
      # 。。。
      globalcors: # 全局的跨域处理
        add-to-simple-url-handler-mapping: true # 解决options请求被拦截问题
        corsConfigurations:
          '[/**]':
            allowedOrigins: # 允许哪些网站的跨域请求 
              - "http://localhost:5500"
            allowedMethods: # 允许的跨域ajax的请求方式
              - "GET"
              - "POST"
              - "DELETE"
              - "PUT"
              - "OPTIONS"
            allowedHeaders: "*" # 允许在请求中携带的头信息
            allowCredentials: true # 是否允许携带cookie
            maxAge: 360000 # 这次跨域检测的有效期
相关推荐
daladongba2 天前
Spring Cloud Gateway
java·spring cloud·gateway
潞哥的博客4 天前
Ingress nginx退役,该怎么换,gateway api 上线
运维·gateway·k8s
Gold Steps.6 天前
K8s Gateway-API 标准化流量治理
容器·kubernetes·gateway
J_liaty6 天前
Spring Cloud Gateway与LoadBalancer深度整合实战:从基础到进阶
spring·spring cloud·gateway·loadbalancer
L***d6707 天前
SpringColoud GateWay 核心组件
gateway
悟空码字7 天前
Spring Cloud Gateway实战,从零搭建API网关,构建高性能微服务统一入口
java·gateway·springcloud·编程技术·后端开发
i***13247 天前
SpringCloud实战十三:Gateway之 Spring Cloud Gateway 动态路由
java·spring cloud·gateway
9***g6877 天前
SpringCloud Gateway 集成 Sentinel 详解 及实现动态监听Nacos规则配置实时更新流控规则
spring cloud·gateway·sentinel
lhrimperial11 天前
深入浅出Spring Cloud Gateway:从理论到企业级实践(一)
spring cloud·微服务·系统架构·gateway
lhrimperial11 天前
深入浅出Spring Cloud Gateway:从理论到企业级实践(二)
spring cloud·微服务·系统架构·gateway