Я ищу способ настройки https для приложения Ktor.
Я нашел там официальную документацию: https://ktor.io/servers/self-signed-certificate.html Здесь объясняется, как добавить ссылки на сертификаты в конфигурации HOCON. файл.
Можно ли настроить ssl без файла конфигурации?
Вот моя кодовая база:
http = embeddedServer(Netty, port = listenPort, configure = {
connectionGroupSize = 1
workerGroupSize = 5
}){
if(sslCertificate != null) {
install(HttpsRedirect) {
sslPort = 443
}
}
install(StatusPages) {
exception<NotFoundError> { cause ->
logger.error("NotFoundError:", cause.message)
call.respondText(cause.message ?: "",
ContentType.Text.Plain, HttpStatusCode.NotFound){}
}
exception<BadFormatError> { cause ->
logger.error("BadFormatError:", cause.message)
call.respondText(cause.message ?: "",
ContentType.Text.Plain, HttpStatusCode.BadRequest){}
}
exception<UserMistake> { cause ->
logger.error("UserMistake:", cause.message)
call.respondText(cause.message ?: "",
ContentType.Text.Plain, HttpStatusCode.BadRequest){}
}
exception<OverloadedException> { cause ->
logger.error("OverloadedException:", cause.message)
call.respondText(cause.message ?: "",
ContentType.Text.Plain, HttpStatusCode.ServiceUnavailable){}
}
exception<Exception> { cause ->
logger.error("Exception:", cause.message)
call.respondText(cause.message ?: "",
ContentType.Text.Plain, HttpStatusCode.InternalServerError){}
}
}
intercept(ApplicationCallPipeline.Call) {
call.response.headers.append(HttpHelper.ACCESS_CONTROL_ALLOW_ORIGIN, "*")
call.response.headers.append(HttpHelper.ACCESS_CONTROL_REQUEST_METHOD, "POST, GET, OPTIONS")
// call.response.headers.append(HttpHelper.CONTENT_TYPE, "application/json")
if(call.request.uri.endsWith("/")) {
call.respondRedirect(call.request.uri.dropLast(1))
}
}
}
http.start()