用户中心跨域问题求助~


我的配置


使用两台Centos7.9虚拟机

第一台虚拟机作为前后端服务器,配置静态IP地址为:192.168.160.134

第二台虚拟机作为数据库服务器,配置静态IP地址为:192.168.160.135,测试从本地(192.168.160.133)能够连接

本地VMNET8配置静态地址为:192.168.160.133

使用xshell连接成功,使用脚本安装宝塔

由于没有域名,好像是无法像鱼皮那样设置反向代理和nginx的配置,索性用docker部署。


前端的线上访问地址是这样的

将跨域代码写在了后端

package com.goblin.usercenter.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfg implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
//设置允许跨域的路径
registry.addMapping("/**")
.allowCredentials(true)
.allowedOriginPatterns("*")
//设置允许跨域请求的域名
//.allowedOrigins("http://127.0.0.1:80","http://192.168.160.134:80")
//设置允许的方法
.allowedMethods("GET","POST","PUT","DELETE","OPTIONS");
}
}

然后无法起作用,前端依旧是403 forbidden,何解???



0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
做条咸鱼
下载 APP