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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-offline",
3
- "version": "14.2.0",
3
+ "version": "14.3.0",
4
4
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
5
5
  "license": "MIT",
6
6
  "exports": {
@@ -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.",
@@ -20,6 +20,7 @@ export default {
20
20
  noPrependStageInUrl: false,
21
21
  noTimeout: false,
22
22
  prefix: "",
23
+ preLoadModules: "",
23
24
  reloadHandler: false,
24
25
  resourceRoutes: false,
25
26
  terminateIdleLambdaTime: 60,
@@ -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 = "502"
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 = "502"
658
+ errorStatusCode = "500"
659
659
  }
660
660
 
661
661
  // Mocks Lambda errors
662
662
  result = {
663
- errorMessage,
664
- errorType: err.constructor.name,
665
- stackTrace: this.#getArrayStackTrace(err.stack),
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,9 +104,9 @@ export default class PythonRunner {
104
104
  })
105
105
 
106
106
  const onErr = (data) => {
107
- // TODO
108
-
109
107
  log.notice(data.toString())
108
+
109
+ rej(new Error("Internal Server Error"))
110
110
  }
111
111
 
112
112
  const onLine = (line) => {
@@ -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