Skip to content

Commit

Permalink
feat: secure web sockets (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
d10-cc authored Sep 22, 2022
1 parent 0000ba7 commit 311fc52
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/events/websocket/HttpServer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { exit } from 'node:process'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { Server } from '@hapi/hapi'
import { log } from '@serverless/utils/log.js'
import { catchAllRoute, connectionsRoutes } from './http-routes/index.js'
Expand All @@ -14,7 +16,7 @@ export default class HttpServer {
this.#options = options
this.#webSocketClients = webSocketClients

const { host, websocketPort } = options
const { host, websocketPort, httpsProtocol } = options

const serverOptions = {
host,
Expand All @@ -26,6 +28,14 @@ export default class HttpServer {
},
}

// HTTPS support
if (typeof httpsProtocol === 'string' && httpsProtocol.length > 0) {
serverOptions.tls = {
cert: readFileSync(resolve(httpsProtocol, 'cert.pem'), 'ascii'),
key: readFileSync(resolve(httpsProtocol, 'key.pem'), 'ascii'),
}
}

this.#server = new Server(serverOptions)
}

Expand Down

0 comments on commit 311fc52

Please sign in to comment.