Skip to content

Commit

Permalink
文件服务本地资源允许跨域访问
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzongzhuan committed Jul 31, 2021
1 parent f112133 commit 370c53e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

Expand Down Expand Up @@ -33,4 +34,17 @@ public void addResourceHandlers(ResourceHandlerRegistry registry)
registry.addResourceHandler(localFilePrefix + "/**")
.addResourceLocations("file:" + localFilePath + File.separator);
}

/**
* 开启跨域
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路由
registry.addMapping(localFilePrefix + "/**")
// 设置允许跨域请求的域名
.allowedOrigins("*")
// 设置允许的方法
.allowedMethods("GET");
}
}

0 comments on commit 370c53e

Please sign in to comment.