-
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (28 loc) · 1017 Bytes
/
index.js
File metadata and controls
34 lines (28 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
// SPDX-License-Identifier: MIT
const httpEventNormalizerMiddleware = () => {
const httpEventNormalizerMiddlewareBefore = (request) => {
const { event } = request;
const version = pickVersion(event);
// VPC Lattice is an http event, however uses a different notation
// - query_string_parameters
// - is_base64_encoded
if (version === "1.0") {
event.multiValueQueryStringParameters ??= {};
} else if (version === "vpc") {
event.queryStringParameters = event.query_string_parameters;
event.isBase64Encoded = event.is_base64_encoded;
}
// event.headers ??= {} // Will always have at least one header
event.pathParameters ??= {};
event.queryStringParameters ??= {};
};
return {
before: httpEventNormalizerMiddlewareBefore,
};
};
const pickVersion = (event) => {
// '1.0' is a safer default
return event.version ?? (event.method ? "vpc" : "1.0");
};
export default httpEventNormalizerMiddleware;