@yopdev/dev-server 2.0.0-beta.4 → 2.0.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.
|
@@ -11,7 +11,7 @@ exports.newLambdaProxyFromCloudFormationTemplate = newLambdaProxyFromCloudFormat
|
|
|
11
11
|
class CloudFormationLambdaProxy extends cloudformation_1.CloudFormationSetup {
|
|
12
12
|
constructor(name, settings, extraRoutes, payloadVersion, config, callback) {
|
|
13
13
|
super(name, (event) => event.Type === 'HttpApi', async (event, handler) => Promise.resolve(this.pathWithCapturingGroups(event.Properties.Path)).then((pathWithCapturingGroups) => ({
|
|
14
|
-
method: new RegExp(event.Properties.Method),
|
|
14
|
+
method: new RegExp(this.method(event.Properties.Method)),
|
|
15
15
|
path: new RegExp(`^${pathWithCapturingGroups}${QUERY_STRING_OR_LOCATION_REG_EXP}?$`),
|
|
16
16
|
weight: this.computeWeight(pathWithCapturingGroups),
|
|
17
17
|
handler: this.pathParameterCapture(new RegExp(pathWithCapturingGroups), handler, config.context),
|
|
@@ -36,6 +36,22 @@ class CloudFormationLambdaProxy extends cloudformation_1.CloudFormationSetup {
|
|
|
36
36
|
.map(([k, v]) => [k, decodeURIComponent(v)])));
|
|
37
37
|
return handler(event, context?.());
|
|
38
38
|
};
|
|
39
|
+
this.method = (cloudFormationValue) => {
|
|
40
|
+
switch (cloudFormationValue) {
|
|
41
|
+
case 'ANY':
|
|
42
|
+
return '.*';
|
|
43
|
+
case 'HEAD':
|
|
44
|
+
case 'OPTIONS':
|
|
45
|
+
case 'GET':
|
|
46
|
+
case 'POST':
|
|
47
|
+
case 'PUT':
|
|
48
|
+
case 'DELETE':
|
|
49
|
+
case 'PATCH':
|
|
50
|
+
return cloudFormationValue;
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`unsupported method ${cloudFormationValue}`);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
39
55
|
this.mapper = payloadVersion.mapper;
|
|
40
56
|
this.authorizer = config?.authorizer;
|
|
41
57
|
this.pathParameterResolver = payloadVersion.resolver;
|
|
@@ -30,9 +30,9 @@ class LambdaHttpProxy {
|
|
|
30
30
|
(0, responses_1.internalServerError)(response, e.body);
|
|
31
31
|
});
|
|
32
32
|
}, (e) => e === exports.UNAUTHORIZED ? (0, responses_1.writeResponse)(response, 401, '') : (0, responses_1.internalServerError)(response, e)));
|
|
33
|
-
this.fallback = async (request, _, response) => Promise.resolve(this.LOGGER.warn(
|
|
34
|
-
this.resolveRoute = (request, body, response) => (this.routes.filter((r) =>
|
|
35
|
-
.filter((r) =>
|
|
33
|
+
this.fallback = async (request, _, response) => Promise.resolve(this.LOGGER.warn(`FALLBACK: ${request.method} to ${request.url}`)).then(() => (0, responses_1.writeResponse)(response, 404, `no route found to handle ${request.method} to ${request.url}`));
|
|
34
|
+
this.resolveRoute = (request, body, response) => (this.routes.filter((r) => r.method.test(request.method))
|
|
35
|
+
.filter((r) => r.path.test(request.url))
|
|
36
36
|
.sort((r1, r2) => r2.weight - r1.weight)
|
|
37
37
|
.map((r) => this.handler(r.authorizer ?? this.defaultAuthorizer, r.handler))
|
|
38
38
|
.find(() => true) ?? this.fallback)(request, body, response);
|