Self-Signed Certificate
Ktor allows you to create and use self-signed certificates for serving HTTPS or HTTP/2 requests.
To create a self-signed certificate using Ktor, you have to call the function.
One possible option is to execute the main class generating the certificate before actually running the server:
You can declare a class with a main method that only generates the certificate when it doesn’t exist:
In your build.gradle
file you can make the task to depend on a generateJks
task that executes the main class generating the certificate. For example:
:
After that you can just write a normal plain Ktor module:
Then you can point to to access your server. Since this is a self-signed certificate, your browser will probably warn you about an invalid certificate, so you will have to disable that warning.