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 小时前
深入理解 Gateway 网关:原理、源码解析与最佳实践
java·spring·gateway
DO_Community6 小时前
DigitalOcean Kubernetes 现已支持 Gateway API 托管服务
容器·kubernetes·gateway
T_Ghost6 小时前
SpringCloud微服务网关Gateway
spring cloud·微服务·gateway
Rysxt_2 天前
Spring Boot Gateway 教程:从入门到精通
spring boot·网关·gateway
月夕·花晨2 天前
Gateway -网关
java·服务器·分布式·后端·spring cloud·微服务·gateway
sanggou3 天前
License 集成 Spring Gateway:解决 WebFlux 非阻塞与 Spring MVC Servlet 阻塞兼容问题
spring·gateway·mvc
摘星编程9 天前
Nginx 502 Bad Gateway:从 upstream 日志到 FastCGI 超时复盘
网络·nginx·gateway·php-fpm·fastcgi
网硕互联的小客服9 天前
504 Gateway Timeout:服务器作为网关或代理时未能及时获得响应如何处理?
运维·服务器·gateway
Pierre_9 天前
通过SpringCloud Gateway实现API接口镜像请求(陪跑)网关功能
spring·spring cloud·gateway
kk在加油10 天前
智能门卫:Gateway
gateway