From d07b6f9b84d87c8a022e274e1505d0c9d750b52f Mon Sep 17 00:00:00 2001 From: Marcin Krzyzanowski Date: Thu, 29 Sep 2022 04:02:50 +0200 Subject: [PATCH] Use SSL_CERT_PATH,SSL_KEY_PATH --- Sources/App/configure.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 2cb7a90..0d50134 100644 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -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())