Skip to content

Commit

Permalink
Use SSL_CERT_PATH,SSL_KEY_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Sep 29, 2022
1 parent b99d607 commit d07b6f9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import NIOSSL

public extension Application {
func configure() throws {

http.server.configuration.port = 80
http.server.configuration.reuseAddress = true

if FileManager.default.fileExists(atPath: directory.workingDirectory + "/ssl/private.key") {
if let certPath = Environment.get("SSL_CERT_PATH"), let keyPath = Environment.get("SSL_KEY_PATH") {
try http.server.configuration.tlsConfiguration = .makeServerConfiguration(
certificateChain: NIOSSLCertificate.fromPEMFile(directory.workingDirectory + "/ssl/certificate.crt").map { .certificate($0) },
privateKey: .privateKey(.init(file: directory.workingDirectory + "/ssl/private.key", format: .pem))
certificateChain: NIOSSLCertificate.fromPEMFile(certPath).map { .certificate($0) },
privateKey: .privateKey(.init(file: keyPath, format: .pem))
)
http.server.configuration.port = 443
}

middleware.use(NotFoundMiddleware())
Expand Down

0 comments on commit d07b6f9

Please sign in to comment.