Skip to content

Commit d8289d2

Browse files
iliaxiliax
andauthored
CORS configuration bean added (#3529)
Co-authored-by: iliax <[email protected]>
1 parent 75a6282 commit d8289d2

File tree

1 file changed

+1
-41
lines changed

1 file changed

+1
-41
lines changed
Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
package com.provectus.kafka.ui.config;
22

3-
import lombok.AllArgsConstructor;
4-
import org.springframework.boot.autoconfigure.web.ServerProperties;
5-
import org.springframework.context.annotation.Bean;
63
import org.springframework.context.annotation.Configuration;
7-
import org.springframework.context.annotation.Profile;
8-
import org.springframework.core.io.ClassPathResource;
9-
import org.springframework.util.StringUtils;
104
import org.springframework.web.reactive.config.CorsRegistry;
115
import org.springframework.web.reactive.config.WebFluxConfigurer;
12-
import org.springframework.web.reactive.function.server.RouterFunction;
13-
import org.springframework.web.reactive.function.server.RouterFunctions;
14-
import org.springframework.web.reactive.function.server.ServerResponse;
156

167
@Configuration
17-
@Profile("local")
18-
@AllArgsConstructor
198
public class CorsGlobalConfiguration implements WebFluxConfigurer {
209

21-
private final ServerProperties serverProperties;
22-
2310
@Override
2411
public void addCorsMappings(CorsRegistry registry) {
2512
registry.addMapping("/**")
@@ -28,31 +15,4 @@ public void addCorsMappings(CorsRegistry registry) {
2815
.allowedHeaders("*")
2916
.allowCredentials(false);
3017
}
31-
32-
private String withContext(String pattern) {
33-
final String basePath = serverProperties.getServlet().getContextPath();
34-
if (StringUtils.hasText(basePath)) {
35-
return basePath + pattern;
36-
} else {
37-
return pattern;
38-
}
39-
}
40-
41-
@Bean
42-
public RouterFunction<ServerResponse> cssFilesRouter() {
43-
return RouterFunctions
44-
.resources(withContext("/static/css/**"), new ClassPathResource("static/static/css/"));
45-
}
46-
47-
@Bean
48-
public RouterFunction<ServerResponse> jsFilesRouter() {
49-
return RouterFunctions
50-
.resources(withContext("/static/js/**"), new ClassPathResource("static/static/js/"));
51-
}
52-
53-
@Bean
54-
public RouterFunction<ServerResponse> mediaFilesRouter() {
55-
return RouterFunctions
56-
.resources(withContext("/static/media/**"), new ClassPathResource("static/static/media/"));
57-
}
58-
}
18+
}

0 commit comments

Comments
 (0)