Created
August 12, 2020 06:43
-
-
Save clonekim/9cfc77dd09936aeccbf603c7a839ad1e to your computer and use it in GitHub Desktop.
Simple Javalin
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
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