This commit is contained in:
Stéphane Nicoll 2024-02-13 18:39:41 +01:00
parent 68189f3de9
commit 48da9524c3
2 changed files with 34 additions and 34 deletions

View File

@ -802,25 +802,25 @@ Java::
+ +
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
---- ----
ClassPathResource index = new ClassPathResource("static/index.html"); ClassPathResource index = new ClassPathResource("static/index.html");
List<String> extensions = List.of("js", "css", "ico", "png", "jpg", "gif"); List<String> extensions = List.of("js", "css", "ico", "png", "jpg", "gif");
RequestPredicate spaPredicate = path("/api/**").or(path("/error")).or(pathExtension(extensions::contains)).negate(); RequestPredicate spaPredicate = path("/api/**").or(path("/error")).or(pathExtension(extensions::contains)).negate();
RouterFunction<ServerResponse> redirectToIndex = route() RouterFunction<ServerResponse> redirectToIndex = route()
.resource(spaPredicate, index) .resource(spaPredicate, index)
.build(); .build();
---- ----
Kotlin:: Kotlin::
+ +
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
---- ----
val redirectToIndex = router { val redirectToIndex = router {
val index = ClassPathResource("static/index.html") val index = ClassPathResource("static/index.html")
val extensions = listOf("js", "css", "ico", "png", "jpg", "gif") val extensions = listOf("js", "css", "ico", "png", "jpg", "gif")
val spaPredicate = !(path("/api/**") or path("/error") or val spaPredicate = !(path("/api/**") or path("/error") or
pathExtension(extensions::contains)) pathExtension(extensions::contains))
resource(spaPredicate, index) resource(spaPredicate, index)
} }
---- ----
====== ======
@ -835,16 +835,16 @@ Java::
+ +
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
---- ----
Resource location = new FileSystemResource("public-resources/"); Resource location = new FileSystemResource("public-resources/");
RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location); RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location);
---- ----
Kotlin:: Kotlin::
+ +
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
---- ----
val location = FileSystemResource("public-resources/") val location = FileSystemResource("public-resources/")
val resources = router { resources("/resources/**", location) } val resources = router { resources("/resources/**", location) }
---- ----
====== ======

View File

@ -780,25 +780,25 @@ Java::
+ +
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
---- ----
ClassPathResource index = new ClassPathResource("static/index.html"); ClassPathResource index = new ClassPathResource("static/index.html");
List<String> extensions = List.of("js", "css", "ico", "png", "jpg", "gif"); List<String> extensions = List.of("js", "css", "ico", "png", "jpg", "gif");
RequestPredicate spaPredicate = path("/api/**").or(path("/error")).or(pathExtension(extensions::contains)).negate(); RequestPredicate spaPredicate = path("/api/**").or(path("/error")).or(pathExtension(extensions::contains)).negate();
RouterFunction<ServerResponse> redirectToIndex = route() RouterFunction<ServerResponse> redirectToIndex = route()
.resource(spaPredicate, index) .resource(spaPredicate, index)
.build(); .build();
---- ----
Kotlin:: Kotlin::
+ +
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
---- ----
val redirectToIndex = router { val redirectToIndex = router {
val index = ClassPathResource("static/index.html") val index = ClassPathResource("static/index.html")
val extensions = listOf("js", "css", "ico", "png", "jpg", "gif") val extensions = listOf("js", "css", "ico", "png", "jpg", "gif")
val spaPredicate = !(path("/api/**") or path("/error") or val spaPredicate = !(path("/api/**") or path("/error") or
pathExtension(extensions::contains)) pathExtension(extensions::contains))
resource(spaPredicate, index) resource(spaPredicate, index)
} }
---- ----
====== ======
@ -813,16 +813,16 @@ Java::
+ +
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
---- ----
Resource location = new FileSystemResource("public-resources/"); Resource location = new FileSystemResource("public-resources/");
RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location); RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location);
---- ----
Kotlin:: Kotlin::
+ +
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
---- ----
val location = FileSystemResource("public-resources/") val location = FileSystemResource("public-resources/")
val resources = router { resources("/resources/**", location) } val resources = router { resources("/resources/**", location) }
---- ----
====== ======