-
-
Save saltyJeff/62a2e865f73cc31d446543dabc6b4d87 to your computer and use it in GitHub Desktop.
Ktor App Code
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.main() { | |
val log = LoggerFactory.getLogger("Main App") | |
install(DefaultHeaders) | |
install(CallLogging) | |
install(ContentNegotiation) { | |
register(ContentType.Application.Json, GsonConverter()) | |
} | |
install(StatusPages) { | |
exception<Throwable> { cause -> | |
log.error("Unhandled error", cause) | |
val status = when (cause) { | |
is AccessControlException -> HttpStatusCode.Forbidden | |
else -> HttpStatusCode.InternalServerError | |
} | |
call.respondText("Error: ${cause}", status = status) | |
} | |
} | |
install(Authentication) { | |
basic { | |
realm = "Y U NO WORK" | |
validate { credentials -> | |
null | |
} | |
} | |
} | |
routing { | |
authenticate { | |
get("/posts/{path}") { | |
val path = call.parameters["path"] | |
val principal = call.authentication.principal<UserIdPrincipal>()!! | |
call.respond (HttpStatusCode.Accepted) //if I replace this with call.respondText, it can listen for HTTP requests | |
//but if it is call.respond(Any), it dies before it can even start listening | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment