33 lines
1.1 KiB
Java
33 lines
1.1 KiB
Java
package com.car.config;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
@Configuration
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
private final String uploadDir;
|
|
|
|
public WebConfig(org.springframework.core.env.Environment environment) {
|
|
this.uploadDir = environment.getProperty("file.upload-dir", "");
|
|
}
|
|
|
|
@Override
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
registry.addMapping("/**")
|
|
.allowedOriginPatterns("*")
|
|
.allowedMethods("*")
|
|
.allowedHeaders("*")
|
|
.allowCredentials(true);
|
|
}
|
|
|
|
@Override
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
if (!uploadDir.isBlank()) {
|
|
String location = "file:" + (uploadDir.endsWith("/") ? uploadDir : uploadDir + "/");
|
|
registry.addResourceHandler("/uploads/**").addResourceLocations(location);
|
|
}
|
|
}
|
|
}
|