add
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
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("/**")
|
||||
@@ -14,4 +21,12 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
if (!uploadDir.isBlank()) {
|
||||
String location = "file:" + (uploadDir.endsWith("/") ? uploadDir : uploadDir + "/");
|
||||
registry.addResourceHandler("/uploads/**").addResourceLocations(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user