11package 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 ;
63import 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 ;
104import org .springframework .web .reactive .config .CorsRegistry ;
115import 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
198public 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