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 # 这次跨域检测的有效期
相关推荐
暗夜猎手-大魔王6 小时前
转载--AI Agent 架构设计:Gateway 架构设计(OpenClaw、Claude Code、Hermes Agent 对比)
gateway
SarL EMEN7 小时前
Gateway Timeout504 网关超时的完美解决方法
gateway
2601_949194261 天前
Gateway Timeout504 网关超时的完美解决方法
gateway
码点滴2 天前
私有 Gateway 接入企业 IM:从消息路由到多租户隔离——Hermes Agent 工程实战
人工智能·架构·gateway·prompt·智能体·hermes
代码写到35岁2 天前
Gateway+OpenFeign 踩坑总结
gateway
invicinble2 天前
对于gateway信息量沉淀
gateway
郝开3 天前
Spring Cloud Gateway 3.5.14 使用手册
java·数据库·spring boot·gateway
Ribou4 天前
Kubernetes v1.35.2 基于 Cilium Gateway API 的服务访问架构
架构·kubernetes·gateway
huipeng9265 天前
GateWay使用详解
java·spring boot·spring cloud·微服务·gateway
随风,奔跑9 天前
Spring Cloud Alibaba(四)---Spring Cloud Gateway
后端·spring·gateway