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.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Configuration;
|
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.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
@ -13,17 +14,28 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
@Value("${file.upload.directory}")
|
@Value("${file.upload.directory}")
|
||||||
private String uploadDirectory;
|
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
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
// Make sure the path ends with a separator
|
|
||||||
String uploadPath = uploadDirectory;
|
String uploadPath = uploadDirectory;
|
||||||
if (!uploadPath.endsWith(File.separator)) {
|
if (!uploadPath.endsWith(File.separator)) {
|
||||||
uploadPath += File.separator;
|
uploadPath += File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve uploaded files publicly at /uploads/**
|
|
||||||
registry.addResourceHandler("/uploads/**")
|
registry.addResourceHandler("/uploads/**")
|
||||||
.addResourceLocations("file:" + uploadPath)
|
.addResourceLocations("file:" + uploadPath)
|
||||||
.setCachePeriod(3600); // Cache for 1 hour
|
.setCachePeriod(3600);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user