Skip to content

Instantly share code, notes, and snippets.

@clonekim
Created August 12, 2020 06:43
Show Gist options
  • Save clonekim/9cfc77dd09936aeccbf603c7a839ad1e to your computer and use it in GitHub Desktop.
Save clonekim/9cfc77dd09936aeccbf603c7a839ad1e to your computer and use it in GitHub Desktop.
Simple Javalin
import io.javalin.Javalin
import io.javalin.http.Context
import io.javalin.apibuilder.ApiBuilder.get
import io.javalin.apibuilder.ApiBuilder.path
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.ServerConnector
import org.eclipse.jetty.util.thread.QueuedThreadPool
object IndexController {
fun index(ctx: Context) {
ctx.json(mapOf(
"name" to "javalin"
))
}
}
fun main(args: Array<String>) {
val app = Javalin.create { config ->
run {
config.defaultContentType = "application/json"
// config.enableDevLogging()
config.server {
Server(QueuedThreadPool(200, 8, 120_000)).apply {
connectors = arrayOf(ServerConnector(server).apply {
port = 7000
idleTimeout = 120_000
})
}
}
}
}.events {
it.serverStarted {
println("!!!")
}
}.start()
app.routes {
path("/") {
get(IndexController::index)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment