Skip to content

Instantly share code, notes, and snippets.

@NikkyAI
Last active October 15, 2020 14:47
Show Gist options
  • Save NikkyAI/6cfbaf4416488913cba9950e1076918a to your computer and use it in GitHub Desktop.
Save NikkyAI/6cfbaf4416488913cba9950e1076918a to your computer and use it in GitHub Desktop.
import io.ktor.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import kotlinx.coroutines.*
import java.util.concurrent.TimeUnit
// start embedded server and close gracefully
fun main(args: Array<String>) {
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
val server = embeddedServer(
factory = Netty,
port = System.getenv("PORT")?.toIntOrNull() ?: 8081,
host = System.getenv("HOST") ?: "localhost",
watchPaths = listOf("jvm/main"),
module = Application::application,
configure = {
}
).start(false)
Runtime.getRuntime().addShutdownHook(Thread {
server.stop(1, 5, TimeUnit.SECONDS)
})
Thread.currentThread().join()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment