forked from gaia-app/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π : add controller to manage natural routes for frontend
- Loading branch information
1 parent
ebb886c
commit 9f9090c
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/main/java/io/codeka/gaia/client/controller/ClientForwardController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.codeka.gaia.client.controller | ||
|
||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
|
||
@Controller | ||
class ClientForwardController { | ||
|
||
@RequestMapping("/**/{path:[^\\.]*}") | ||
fun redirect(): String = "forward:/" | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/io/codeka/gaia/client/controller/ClientForwardControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.codeka.gaia.client.controller | ||
|
||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.http.MediaType | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
class ClientForwardControllerTest { | ||
|
||
lateinit var mockMvc: MockMvc | ||
|
||
@BeforeEach | ||
fun setup() { | ||
mockMvc = MockMvcBuilders | ||
.standaloneSetup(ClientForwardController(), TestController()) | ||
.build() | ||
} | ||
|
||
@Test | ||
fun `clientForwardController should forward to home page for unknown mapping`() { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/path/to/go")) | ||
.andExpect(MockMvcResultMatchers.status().isOk) | ||
.andExpect(MockMvcResultMatchers.forwardedUrl("/")) | ||
} | ||
|
||
@Test | ||
fun `clientForwardController should ignore backend`() { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/test")) | ||
.andExpect(MockMvcResultMatchers.status().isOk) | ||
.andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN_VALUE)) | ||
.andExpect(MockMvcResultMatchers.content().string("test")) | ||
} | ||
|
||
@RestController | ||
class TestController { | ||
|
||
@RequestMapping("/api/test") | ||
fun test(): String = "test" | ||
|
||
} | ||
|
||
} |