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 # 这次跨域检测的有效期
相关推荐
yuluo_YX13 天前
AI Gateway 介绍
人工智能·gateway
网硕互联的小客服15 天前
502 Bad Gateway:服务器作为网关或代理时收到无效响应处理方式
运维·服务器·gateway
sevevty-seven16 天前
什么是Gateway
gateway
秋の花16 天前
【GateWay】和权限验证
java·gateway
欧先生^_^17 天前
org.springframework.cloud.gateway 组件解释
gateway
jarenyVO19 天前
Spring Cloud Gateway 全面学习指南
java·gateway
保持学习ing21 天前
微服务--Gateway网关
java·网关·微服务·gateway
SZ17011023122 天前
IGP(Interior Gateway Protocol,内部网关协议)
运维·服务器·gateway
肥仔哥哥193022 天前
SpringCloud2025+SpringBoot3.5.0+gateway+webflux子服务路由报503
微服务·gateway·最新微服务
亚林瓜子1 个月前
AWS API Gateway配置日志
云计算·gateway·aws·log·cloudwatch