Created
July 28, 2020 20:50
-
-
Save mathias21/c4361419b8738944ab19ab2729ca6893 to your computer and use it in GitHub Desktop.
KtorEasy server setup
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
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