Skip to content

Commit

Permalink
refactor: load certs private method
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Aug 8, 2022
1 parent 2b2a8fa commit 33e4e01
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default class HttpServer {
this.#serverless = serverless
}

async #loadCerts(httpsProtocol) {
const [cert, key] = await Promise.all([
readFile(resolve(httpsProtocol, 'cert.pem'), 'utf-8'),
readFile(resolve(httpsProtocol, 'key.pem'), 'utf-8'),
])

return [cert, key]
}

async createServer() {
const {
enforceSecureCookies,
Expand Down Expand Up @@ -81,10 +90,7 @@ export default class HttpServer {

// https support
if (httpsProtocol) {
const [cert, key] = await Promise.all([
readFile(resolve(httpsProtocol, 'cert.pem'), 'utf-8'),
readFile(resolve(httpsProtocol, 'key.pem'), 'utf-8'),
])
const [cert, key] = await this.#loadCerts(httpsProtocol)

serverOptions.tls = {
cert,
Expand Down Expand Up @@ -1017,7 +1023,9 @@ export default class HttpServer {
auth: authStrategyName,
cors,
state,
timeout: { socket: false },
timeout: {
socket: false,
},
}

// skip HEAD routes as hapi will fail with 'Method name not allowed: HEAD ...'
Expand Down

0 comments on commit 33e4e01

Please sign in to comment.