Skip to content

Instantly share code, notes, and snippets.

@mathias21
Created July 28, 2020 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathias21/c4361419b8738944ab19ab2729ca6893 to your computer and use it in GitHub Desktop.
Save mathias21/c4361419b8738944ab19ab2729ca6893 to your computer and use it in GitHub Desktop.
KtorEasy server setup
fun Application.module() {
val userApi by inject<UserApi>()
val databaseProvider by inject<DatabaseProviderContract>()
val jwtVerifier by inject<JWTVerifier>()
//Init database here
databaseProvider.init()
install(CallLogging) {
level = Level.DEBUG
}
install(ContentNegotiation) { gson { } }
install(StatusPages) {
generalStatusPages()
userStatusPages()
authStatusPages()
exception<UnknownError> {
call.respondText(
"Internal server error",
ContentType.Text.Plain,
status = HttpStatusCode.InternalServerError
)
}
exception<IllegalArgumentException> {
call.respond(HttpStatusCode.BadRequest)
}
}
install(Authentication) {
authenticationModule(userApi, databaseProvider, jwtVerifier)
}
install(Routing) {
static("/static") {
resources("static")
}
registrationModule()
authenticate("jwt") {
userModule()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment