serverless-offline 14.2.0 → 14.3.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/README.md +9 -0
- package/package.json +1 -1
- package/src/ServerlessOffline.js +18 -0
- package/src/config/commandOptions.js +4 -0
- package/src/config/defaultOptions.js +1 -0
- package/src/events/http/HttpServer.js +8 -5
- package/src/lambda/handler-runner/python-runner/PythonRunner.js +2 -2
- package/src/lambda/handler-runner/python-runner/invoke.py +1 -1
package/README.md
CHANGED
|
@@ -195,6 +195,10 @@ Turns off all authorizers.
|
|
|
195
195
|
|
|
196
196
|
Don't prepend http routes with the stage.
|
|
197
197
|
|
|
198
|
+
#### noSponsor
|
|
199
|
+
|
|
200
|
+
Remove sponsor message from the output.
|
|
201
|
+
|
|
198
202
|
#### noTimeout
|
|
199
203
|
|
|
200
204
|
-t Disables the timeout feature.
|
|
@@ -239,6 +243,11 @@ Default: 600 (10 minutes)
|
|
|
239
243
|
WebSocket port to listen on.<br />
|
|
240
244
|
Default: 3001
|
|
241
245
|
|
|
246
|
+
#### preLoadModules
|
|
247
|
+
|
|
248
|
+
Pre-load specified modules in the main thread to avoid crashes when importing in worker threads. Provide module names as a comma-separated list (e.g., "sharp,canvas").<br />
|
|
249
|
+
Default: ''
|
|
250
|
+
|
|
242
251
|
Any of the CLI options can be added to your `serverless.yml`. For example:
|
|
243
252
|
|
|
244
253
|
```yml
|
package/package.json
CHANGED
package/src/ServerlessOffline.js
CHANGED
|
@@ -65,6 +65,8 @@ export default class ServerlessOffline {
|
|
|
65
65
|
async start() {
|
|
66
66
|
this.#mergeOptions()
|
|
67
67
|
|
|
68
|
+
this.#preLoadModules()
|
|
69
|
+
|
|
68
70
|
if (this.#cliOptions.noSponsor) {
|
|
69
71
|
log.notice()
|
|
70
72
|
} else {
|
|
@@ -423,6 +425,18 @@ export default class ServerlessOffline {
|
|
|
423
425
|
}
|
|
424
426
|
}
|
|
425
427
|
|
|
428
|
+
#preLoadModules() {
|
|
429
|
+
const modules = this.#options.preLoadModules.split(",")
|
|
430
|
+
|
|
431
|
+
modules.forEach((module) => {
|
|
432
|
+
try {
|
|
433
|
+
import(module)
|
|
434
|
+
} catch (error) {
|
|
435
|
+
log.error(`Error importing module ${module}: ${error}`)
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
|
|
426
440
|
// TODO FIXME
|
|
427
441
|
// TEMP quick fix to expose for testing, look for better solution
|
|
428
442
|
internals() {
|
|
@@ -446,6 +460,10 @@ export default class ServerlessOffline {
|
|
|
446
460
|
mergeOptions: () => {
|
|
447
461
|
this.#mergeOptions()
|
|
448
462
|
},
|
|
463
|
+
|
|
464
|
+
preLoadModules: () => {
|
|
465
|
+
this.#preLoadModules()
|
|
466
|
+
},
|
|
449
467
|
}
|
|
450
468
|
}
|
|
451
469
|
}
|
|
@@ -104,6 +104,10 @@ export default {
|
|
|
104
104
|
usage:
|
|
105
105
|
"Adds a prefix to every path, to send your requests to http://localhost:3000/prefix/[your_path] instead.",
|
|
106
106
|
},
|
|
107
|
+
preLoadModules: {
|
|
108
|
+
type: "string",
|
|
109
|
+
usage: "A comma separated list of modules to preload on the main thread",
|
|
110
|
+
},
|
|
107
111
|
reloadHandler: {
|
|
108
112
|
type: "boolean",
|
|
109
113
|
usage: "Reloads handler with each request.",
|
|
@@ -645,7 +645,7 @@ export default class HttpServer {
|
|
|
645
645
|
/* RESPONSE SELECTION (among endpoint's possible responses) */
|
|
646
646
|
|
|
647
647
|
// Failure handling
|
|
648
|
-
let errorStatusCode = "
|
|
648
|
+
let errorStatusCode = "500"
|
|
649
649
|
|
|
650
650
|
if (err) {
|
|
651
651
|
const errorMessage = (err.message || err).toString()
|
|
@@ -655,14 +655,17 @@ export default class HttpServer {
|
|
|
655
655
|
if (found && found.length > 1) {
|
|
656
656
|
;[, errorStatusCode] = found
|
|
657
657
|
} else {
|
|
658
|
-
errorStatusCode = "
|
|
658
|
+
errorStatusCode = "500"
|
|
659
659
|
}
|
|
660
660
|
|
|
661
661
|
// Mocks Lambda errors
|
|
662
662
|
result = {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
663
|
+
body: JSON.stringify({
|
|
664
|
+
message: errorMessage,
|
|
665
|
+
stackTrace: this.#getArrayStackTrace(err.stack),
|
|
666
|
+
type: err.constructor.name,
|
|
667
|
+
}),
|
|
668
|
+
statusCode: errorStatusCode,
|
|
666
669
|
}
|
|
667
670
|
|
|
668
671
|
log.error(errorMessage)
|
|
@@ -104,7 +104,7 @@ if __name__ == '__main__':
|
|
|
104
104
|
'__offline_payload__': result
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
if isinstance(result['body'], bytes):
|
|
107
|
+
if hasattr(result, 'body') and isinstance(result['body'], bytes):
|
|
108
108
|
data['__offline_payload__']['body'] = base64.b64encode(result['body']).decode('utf-8')
|
|
109
109
|
data['isBase64Encoded'] = True
|
|
110
110
|
|