后台添加过滤器,允许跨域
@Configuration
public class GlobalCorsConfig {
    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");

        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
        configSource.registerCorsConfiguration("/**", corsConfiguration);

        return new CorsFilter(configSource);
    }
}
前台

在config的index.js的proxyTable中加入拦截,拦截/api请求,替换成target中的请求,
比如原始请求是/api/hello.pub,则会替换成http://192.168.33.104:8086/hello.pub。

    proxyTable: {
      '/api':{
        target: 'http://192.168.33.104:8086',
        changeOrigin:true,
        pathRewrite:{
            '^/api':''
        }
      }
    },
Logo

前往低代码交流专区

更多推荐