-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathIndexRouter.kt
47 lines (43 loc) · 1.53 KB
/
IndexRouter.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package todoapp.web
import kotlinx.html.*
import kotlinx.html.stream.appendHTML
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.server.RouterFunction
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.web.reactive.function.server.router
/**
* 인덱스 페이지 라우터
*
* @author [email protected]
*/
class IndexRouter : RouterFunction<ServerResponse> {
private val delegate = router {
accept(MediaType.TEXT_HTML).nest {
GET("/") {
ok().contentType(MediaType.TEXT_HTML).bodyValue(indexHtml)
}
}
}
private val indexHtml = buildString {
appendLine("<!DOCTYPE html>")
appendHTML(xhtmlCompatible = true).html {
head {
title("KMP • TodoMVC")
meta(charset = "utf-8")
link(href = "/webjars/todomvc-common/1.0.5/base.css", rel = "stylesheet")
link(href = "/webjars/todomvc-app-css/2.4.1/index.css", rel = "stylesheet")
}
body {
// TODO 다음 HTML 태그를 작성하세요
// <div id="root"></div>
// <script src="/main.js"></script>
div{
id = "root"
}
script (src="/main.js"){ }
}
}
}
override fun route(request: ServerRequest) = delegate.route(request)
}