lion7 / ktor-server-acme

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ACME connector for Ktor Server 2.0

Example usage

package com.github.lion7.ktor.server.acme

import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.jetty.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import java.io.File

object JettyExample {

    @DelicateCoroutinesApi
    @JvmStatic
    fun main(args: Array<String>) {
        val acmeConnector = acmeConnector(
            certificateAuthority = AcmeCertificateAuthorities.PEBBLE.url,
            accountKeyPairFile = File("acme-account.pem"),
            contact = "acme@example.com",
            agreeToTermsOfService = true,
            domain = "example.com",
            keyStorePath = File("acme-certs.p12"),
            keyStorePassword = { "secret".toCharArray() },
            privateKeyPassword = { "secret".toCharArray() }
        )
        val server = GlobalScope.embeddedServer(factory = Jetty, connectors = arrayOf(acmeConnector), configure = acmeConnector.configure) {
            routing {
                get {
                    call.respond("Hello World!")
                }
            }
        }
        server.start(true)
    }

}

About


Languages

Language:Kotlin 100.0%