serverless-offline 10.3.0 → 10.3.2
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 +4 -4
- package/src/events/http/Http.js +1 -37
- package/src/events/http/HttpServer.js +43 -15
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.3.
|
|
4
|
+
"version": "10.3.2",
|
|
5
5
|
"description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"exports": {
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@hapi/boom": "^10.0.0",
|
|
86
|
-
"@hapi/h2o2": "^
|
|
86
|
+
"@hapi/h2o2": "^10.0.0",
|
|
87
87
|
"@hapi/hapi": "^20.2.2",
|
|
88
88
|
"@serverless/utils": "^6.7.0",
|
|
89
|
-
"aws-sdk": "^2.
|
|
89
|
+
"aws-sdk": "^2.1224.0",
|
|
90
90
|
"boxen": "^7.0.0",
|
|
91
91
|
"chalk": "^5.0.1",
|
|
92
92
|
"execa": "^6.1.0",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"jsonpath-plus": "^7.2.0",
|
|
98
98
|
"jsonschema": "^1.4.1",
|
|
99
99
|
"jszip": "^3.10.1",
|
|
100
|
-
"luxon": "^3.0.
|
|
100
|
+
"luxon": "^3.0.4",
|
|
101
101
|
"node-fetch": "^3.2.10",
|
|
102
102
|
"node-schedule": "^2.1.0",
|
|
103
103
|
"object.hasown": "^1.1.1",
|
package/src/events/http/Http.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import { log } from '@serverless/utils/log.js'
|
|
2
1
|
import HttpEventDefinition from './HttpEventDefinition.js'
|
|
3
2
|
import HttpServer from './HttpServer.js'
|
|
4
|
-
import { orange } from '../../config/colors.js'
|
|
5
|
-
import { createApiKey } from '../../utils/index.js'
|
|
6
3
|
|
|
7
4
|
export default class Http {
|
|
8
|
-
#hasPrivateHttpEvent = false
|
|
9
|
-
|
|
10
5
|
#httpServer = null
|
|
11
6
|
|
|
12
|
-
#options = null
|
|
13
|
-
|
|
14
7
|
constructor(serverless, options, lambda) {
|
|
15
8
|
this.#httpServer = new HttpServer(serverless, options, lambda)
|
|
16
|
-
this.#options = options
|
|
17
9
|
}
|
|
18
10
|
|
|
19
11
|
start() {
|
|
@@ -36,38 +28,10 @@ export default class Http {
|
|
|
36
28
|
}
|
|
37
29
|
|
|
38
30
|
create(events) {
|
|
39
|
-
events.forEach(({ functionKey, handler, http
|
|
31
|
+
events.forEach(({ functionKey, handler, http }) => {
|
|
40
32
|
this.#createEvent(functionKey, http, handler)
|
|
41
|
-
|
|
42
|
-
if (priv) {
|
|
43
|
-
this.#hasPrivateHttpEvent = true
|
|
44
|
-
}
|
|
45
33
|
})
|
|
46
34
|
|
|
47
|
-
if (this.#hasPrivateHttpEvent) {
|
|
48
|
-
if (this.#options.apiKey) {
|
|
49
|
-
log.notice()
|
|
50
|
-
log.warning(
|
|
51
|
-
orange(`'--apiKey' is deprecated and will be removed in the next major version.
|
|
52
|
-
Please define the apiKey value in the 'provider.apiGateway.apiKeys' section of the serverless config.
|
|
53
|
-
If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
|
|
54
|
-
)
|
|
55
|
-
log.notice()
|
|
56
|
-
} else {
|
|
57
|
-
this.#options.apiKey = createApiKey()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
log.notice(`Key with token: ${this.#options.apiKey}`)
|
|
61
|
-
|
|
62
|
-
if (this.#options.noAuth) {
|
|
63
|
-
log.notice(
|
|
64
|
-
`Authorizers are turned off. You do not need to use 'x-api-key' header.`,
|
|
65
|
-
)
|
|
66
|
-
} else {
|
|
67
|
-
log.notice(`Remember to use 'x-api-key' on the request headers.`)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
35
|
this.#httpServer.writeRoutesTerminal()
|
|
72
36
|
}
|
|
73
37
|
|
|
@@ -20,8 +20,10 @@ import {
|
|
|
20
20
|
import LambdaProxyIntegrationEventV2 from './lambda-events/LambdaProxyIntegrationEventV2.js'
|
|
21
21
|
import parseResources from './parseResources.js'
|
|
22
22
|
import payloadSchemaValidator from './payloadSchemaValidator.js'
|
|
23
|
+
import { orange } from '../../config/colors.js'
|
|
23
24
|
import logRoutes from '../../utils/logRoutes.js'
|
|
24
25
|
import {
|
|
26
|
+
createApiKey,
|
|
25
27
|
detectEncoding,
|
|
26
28
|
generateHapiPath,
|
|
27
29
|
getApiKeysValues,
|
|
@@ -36,21 +38,19 @@ const { assign, entries, keys } = Object
|
|
|
36
38
|
export default class HttpServer {
|
|
37
39
|
#apiKeysValues = null
|
|
38
40
|
|
|
41
|
+
#hasPrivateHttpEvent = false
|
|
42
|
+
|
|
39
43
|
#lambda = null
|
|
40
44
|
|
|
41
45
|
#options = null
|
|
42
46
|
|
|
43
|
-
#serverless = null
|
|
44
|
-
|
|
45
47
|
#server = null
|
|
46
48
|
|
|
49
|
+
#serverless = null
|
|
50
|
+
|
|
47
51
|
#terminalInfo = []
|
|
48
52
|
|
|
49
53
|
constructor(serverless, options, lambda) {
|
|
50
|
-
this.#apiKeysValues = getApiKeysValues(
|
|
51
|
-
serverless.service.provider.apiGateway?.apiKeys ?? [],
|
|
52
|
-
)
|
|
53
|
-
|
|
54
54
|
this.#lambda = lambda
|
|
55
55
|
this.#options = options
|
|
56
56
|
this.#serverless = serverless
|
|
@@ -435,10 +435,7 @@ export default class HttpServer {
|
|
|
435
435
|
const apiKey = request.headers['x-api-key']
|
|
436
436
|
|
|
437
437
|
if (apiKey) {
|
|
438
|
-
if (
|
|
439
|
-
apiKey !== this.#options.apiKey &&
|
|
440
|
-
!this.#apiKeysValues.has(apiKey)
|
|
441
|
-
) {
|
|
438
|
+
if (!this.#apiKeysValues.has(apiKey)) {
|
|
442
439
|
log.debug(
|
|
443
440
|
`Method '${method}' of function '${functionKey}' token '${apiKey}' not valid.`,
|
|
444
441
|
)
|
|
@@ -452,10 +449,7 @@ export default class HttpServer {
|
|
|
452
449
|
) {
|
|
453
450
|
const { usageIdentifierKey } = request.auth.credentials
|
|
454
451
|
|
|
455
|
-
if (
|
|
456
|
-
usageIdentifierKey !== this.#options.apiKey &&
|
|
457
|
-
!this.#apiKeysValues.has(usageIdentifierKey)
|
|
458
|
-
) {
|
|
452
|
+
if (!this.#apiKeysValues.has(usageIdentifierKey)) {
|
|
459
453
|
log.debug(
|
|
460
454
|
`Method '${method}' of function '${functionKey}' token '${usageIdentifierKey}' not valid.`,
|
|
461
455
|
)
|
|
@@ -898,7 +892,39 @@ export default class HttpServer {
|
|
|
898
892
|
}
|
|
899
893
|
|
|
900
894
|
createRoutes(functionKey, httpEvent, handler) {
|
|
901
|
-
|
|
895
|
+
if (!this.#hasPrivateHttpEvent && httpEvent.private) {
|
|
896
|
+
this.#hasPrivateHttpEvent = true
|
|
897
|
+
|
|
898
|
+
if (this.#options.apiKey) {
|
|
899
|
+
log.notice()
|
|
900
|
+
log.warning(
|
|
901
|
+
orange(`'--apiKey' is deprecated and will be removed in the next major version.
|
|
902
|
+
Please define the apiKey value in the 'provider.apiGateway.apiKeys' section of the serverless config.
|
|
903
|
+
If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
|
|
904
|
+
)
|
|
905
|
+
log.notice()
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
if (this.#options.noAuth) {
|
|
909
|
+
log.notice(
|
|
910
|
+
`Authorizers are turned off. You do not need to use 'x-api-key' header.`,
|
|
911
|
+
)
|
|
912
|
+
} else {
|
|
913
|
+
log.notice(`Remember to use 'x-api-key' on the request headers.`)
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
if (this.#apiKeysValues == null) {
|
|
917
|
+
const apiKey = this.#options.apiKey ?? createApiKey()
|
|
918
|
+
|
|
919
|
+
log.notice(`Key with token: ${apiKey}`)
|
|
920
|
+
|
|
921
|
+
this.#apiKeysValues = getApiKeysValues(
|
|
922
|
+
this.#serverless.service.provider.apiGateway?.apiKeys ?? [],
|
|
923
|
+
)
|
|
924
|
+
|
|
925
|
+
this.#apiKeysValues.add(apiKey)
|
|
926
|
+
}
|
|
927
|
+
}
|
|
902
928
|
|
|
903
929
|
let method
|
|
904
930
|
let path
|
|
@@ -926,6 +952,8 @@ export default class HttpServer {
|
|
|
926
952
|
hapiPath = generateHapiPath(path, this.#options, this.#serverless)
|
|
927
953
|
}
|
|
928
954
|
|
|
955
|
+
const [handlerPath] = splitHandlerPathAndName(handler)
|
|
956
|
+
|
|
929
957
|
const endpoint = new Endpoint(
|
|
930
958
|
join(this.#serverless.config.servicePath, handlerPath),
|
|
931
959
|
httpEvent,
|