/
NewApiApplication.kt
31 lines (27 loc) · 1.02 KB
/
NewApiApplication.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
package org.apisix.newapi
import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.support.beans
import org.springframework.web.servlet.function.ServerResponse
import org.springframework.web.servlet.function.router
@SpringBootApplication
class NewApiApplication
internal fun beans() = beans {
bean {
router {
(GET("/hello") or GET("/hello/")) { ServerResponse.ok().body("Hello world (souped-up version!)") }
GET("/hello/{who}") { ServerResponse.ok().body("Hello ${it.pathVariable("who")} (souped-up version!)") }
GET("/**") {
val logger = LoggerFactory.getLogger(NewApiApplication::class.java)
logger.warn("Path not found: ${it.path()}")
ServerResponse.notFound().build()
}
}
}
}
fun main(args: Array<String>) {
runApplication<NewApiApplication>(*args) {
addInitializers(beans())
}
}