Image error solve update
This commit is contained in:
@ -2,6 +2,7 @@ package net.shyshkin.study.fullstack.supportportal.backend.config;
|
||||
|
||||
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;
|
||||
|
||||
@ -13,17 +14,28 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
@Value("${file.upload.directory}")
|
||||
private String uploadDirectory;
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins(
|
||||
"https://cmcadminfrontend.rootxwire.com",
|
||||
"https://maincmc.rootxwire.com",
|
||||
"http://localhost:4200"
|
||||
)
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// Make sure the path ends with a separator
|
||||
String uploadPath = uploadDirectory;
|
||||
if (!uploadPath.endsWith(File.separator)) {
|
||||
uploadPath += File.separator;
|
||||
}
|
||||
|
||||
// Serve uploaded files publicly at /uploads/**
|
||||
registry.addResourceHandler("/uploads/**")
|
||||
.addResourceLocations("file:" + uploadPath)
|
||||
.setCachePeriod(3600); // Cache for 1 hour
|
||||
.setCachePeriod(3600);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user