serverless-offline 10.1.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dedicatedTo": "Blue, a great migrating bird.",
|
|
3
3
|
"name": "serverless-offline",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.2.0",
|
|
5
5
|
"description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"exports": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"@hapi/h2o2": "^9.1.0",
|
|
87
87
|
"@hapi/hapi": "^20.2.2",
|
|
88
88
|
"@serverless/utils": "^6.7.0",
|
|
89
|
-
"aws-sdk": "^2.
|
|
89
|
+
"aws-sdk": "^2.1222.0",
|
|
90
90
|
"boxen": "^7.0.0",
|
|
91
91
|
"chalk": "^5.0.1",
|
|
92
92
|
"execa": "^6.1.0",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"p-memoize": "^7.1.0",
|
|
105
105
|
"p-retry": "^5.1.1",
|
|
106
106
|
"velocityjs": "^2.0.6",
|
|
107
|
-
"ws": "^8.
|
|
107
|
+
"ws": "^8.9.0"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
110
|
"@istanbuljs/esm-loader-hook": "^0.2.0",
|
package/src/ServerlessOffline.js
CHANGED
|
@@ -206,9 +206,11 @@ export default class ServerlessOffline {
|
|
|
206
206
|
this.#lambda,
|
|
207
207
|
)
|
|
208
208
|
|
|
209
|
+
await this.#webSocket.createServer()
|
|
210
|
+
|
|
209
211
|
this.#webSocket.create(events)
|
|
210
212
|
|
|
211
|
-
|
|
213
|
+
await this.#webSocket.start()
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
#mergeOptions() {
|
|
@@ -335,7 +337,7 @@ export default class ServerlessOffline {
|
|
|
335
337
|
}
|
|
336
338
|
}
|
|
337
339
|
|
|
338
|
-
if (http
|
|
340
|
+
if (http?.private) {
|
|
339
341
|
hasPrivateHttpEvent = true
|
|
340
342
|
}
|
|
341
343
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
1
3
|
import { exit } from 'node:process'
|
|
2
4
|
import { Server } from '@hapi/hapi'
|
|
3
5
|
import { log } from '@serverless/utils/log.js'
|
|
@@ -13,8 +15,22 @@ export default class HttpServer {
|
|
|
13
15
|
constructor(options, webSocketClients) {
|
|
14
16
|
this.#options = options
|
|
15
17
|
this.#webSocketClients = webSocketClients
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async #loadCerts(httpsProtocol) {
|
|
21
|
+
const [cert, key] = await Promise.all([
|
|
22
|
+
readFile(resolve(httpsProtocol, 'cert.pem'), 'utf-8'),
|
|
23
|
+
readFile(resolve(httpsProtocol, 'key.pem'), 'utf-8'),
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
cert,
|
|
28
|
+
key,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
async createServer() {
|
|
33
|
+
const { host, websocketPort, httpsProtocol } = this.#options
|
|
18
34
|
|
|
19
35
|
const serverOptions = {
|
|
20
36
|
host,
|
|
@@ -24,6 +40,10 @@ export default class HttpServer {
|
|
|
24
40
|
// e.g. : /my-path is the same as /my-path/
|
|
25
41
|
stripTrailingSlash: true,
|
|
26
42
|
},
|
|
43
|
+
// https support
|
|
44
|
+
...(httpsProtocol != null && {
|
|
45
|
+
tls: await this.#loadCerts(httpsProtocol),
|
|
46
|
+
}),
|
|
27
47
|
}
|
|
28
48
|
|
|
29
49
|
this.#server = new Server(serverOptions)
|
|
@@ -6,19 +6,39 @@ import WebSocketServer from './WebSocketServer.js'
|
|
|
6
6
|
export default class WebSocket {
|
|
7
7
|
#httpServer = null
|
|
8
8
|
|
|
9
|
+
#lambda = null
|
|
10
|
+
|
|
11
|
+
#options = null
|
|
12
|
+
|
|
13
|
+
#serverless = null
|
|
14
|
+
|
|
9
15
|
#webSocketServer = null
|
|
10
16
|
|
|
11
17
|
constructor(serverless, options, lambda) {
|
|
12
|
-
|
|
18
|
+
this.#lambda = lambda
|
|
19
|
+
this.#options = options
|
|
20
|
+
this.#serverless = serverless
|
|
21
|
+
}
|
|
13
22
|
|
|
14
|
-
|
|
23
|
+
async createServer() {
|
|
24
|
+
const webSocketClients = new WebSocketClients(
|
|
25
|
+
this.#serverless,
|
|
26
|
+
this.#options,
|
|
27
|
+
this.#lambda,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
this.#httpServer = new HttpServer(this.#options, webSocketClients)
|
|
31
|
+
|
|
32
|
+
await this.#httpServer.createServer()
|
|
15
33
|
|
|
16
34
|
// share server
|
|
17
35
|
this.#webSocketServer = new WebSocketServer(
|
|
18
|
-
options,
|
|
36
|
+
this.#options,
|
|
19
37
|
webSocketClients,
|
|
20
38
|
this.#httpServer.server,
|
|
21
39
|
)
|
|
40
|
+
|
|
41
|
+
await this.#webSocketServer.createServer()
|
|
22
42
|
}
|
|
23
43
|
|
|
24
44
|
start() {
|
|
@@ -7,14 +7,19 @@ export default class WebSocketServer {
|
|
|
7
7
|
|
|
8
8
|
#options = null
|
|
9
9
|
|
|
10
|
+
#sharedServer = null
|
|
11
|
+
|
|
10
12
|
#webSocketClients = null
|
|
11
13
|
|
|
12
14
|
constructor(options, webSocketClients, sharedServer) {
|
|
13
15
|
this.#options = options
|
|
16
|
+
this.#sharedServer = sharedServer
|
|
14
17
|
this.#webSocketClients = webSocketClients
|
|
18
|
+
}
|
|
15
19
|
|
|
20
|
+
async createServer() {
|
|
16
21
|
const server = new WsWebSocketServer({
|
|
17
|
-
server: sharedServer,
|
|
22
|
+
server: this.#sharedServer,
|
|
18
23
|
verifyClient: async ({ req }, cb) => {
|
|
19
24
|
const connectionId = createUniqueId()
|
|
20
25
|
const key = req.headers['sec-websocket-key']
|