@geostrategists/react-router-aws 2.2.0 → 2.3.0-rc.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 +67 -0
- package/dist/index.cjs +352 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +661 -0
- package/dist/index.d.mts +583 -24
- package/dist/index.mjs +302 -305
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -84
- package/biome.json +0 -47
- package/dist/index.d.ts +0 -102
- package/dist/index.js +0 -378
- package/test/alb.test.ts +0 -95
- package/test/apigw-v1.test.ts +0 -101
- package/test/apigw-v2.test.ts +0 -107
- package/test/function-url-streaming.test.ts +0 -107
- package/test/function-url.test.ts +0 -107
- package/test/lambda-stream/HttpResponseStream.ts +0 -34
- package/test/lambda-stream/ResponseStream.ts +0 -44
- package/test/lambda-stream/index.ts +0 -56
- package/test/setup.ts +0 -7
- package/test/utils.ts +0 -69
- package/vitest.config.ts +0 -12
package/dist/index.mjs
CHANGED
|
@@ -1,348 +1,345 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @geostrategists/react-router-aws v2.
|
|
2
|
+
* @geostrategists/react-router-aws v2.3.0-rc.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Geostrategists Consulting GmbH
|
|
5
5
|
*
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"application/x-bzip",
|
|
72
|
-
"application/x-bzip2",
|
|
73
|
-
"application/x-gzip",
|
|
74
|
-
"application/x-java-archive",
|
|
75
|
-
"application/x-rar-compressed",
|
|
76
|
-
"application/x-tar",
|
|
77
|
-
"application/x-zip",
|
|
78
|
-
"application/zip"
|
|
11
|
+
import { createRequestHandler as createRequestHandler$1 } from "react-router";
|
|
12
|
+
import { readableStreamToString, writeReadableStreamToWritable } from "@react-router/node";
|
|
13
|
+
import { URLSearchParams } from "url";
|
|
14
|
+
//#region src/binaryTypes.ts
|
|
15
|
+
/**
|
|
16
|
+
* Common binary MIME types
|
|
17
|
+
* @see https://github.com/architect/functions/blob/45254fc1936a1794c185aac07e9889b241a2e5c6/src/http/helpers/binary-types.js
|
|
18
|
+
*/
|
|
19
|
+
const binaryTypes = [
|
|
20
|
+
"application/octet-stream",
|
|
21
|
+
"application/epub+zip",
|
|
22
|
+
"application/msword",
|
|
23
|
+
"application/pdf",
|
|
24
|
+
"application/rtf",
|
|
25
|
+
"application/vnd.amazon.ebook",
|
|
26
|
+
"application/vnd.ms-excel",
|
|
27
|
+
"application/vnd.ms-powerpoint",
|
|
28
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
29
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
30
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
31
|
+
"font/otf",
|
|
32
|
+
"font/woff",
|
|
33
|
+
"font/woff2",
|
|
34
|
+
"image/avif",
|
|
35
|
+
"image/bmp",
|
|
36
|
+
"image/gif",
|
|
37
|
+
"image/jpeg",
|
|
38
|
+
"image/png",
|
|
39
|
+
"image/tiff",
|
|
40
|
+
"image/vnd.microsoft.icon",
|
|
41
|
+
"image/webp",
|
|
42
|
+
"audio/3gpp",
|
|
43
|
+
"audio/aac",
|
|
44
|
+
"audio/basic",
|
|
45
|
+
"audio/mpeg",
|
|
46
|
+
"audio/ogg",
|
|
47
|
+
"audio/wav",
|
|
48
|
+
"audio/webm",
|
|
49
|
+
"audio/x-aiff",
|
|
50
|
+
"audio/x-midi",
|
|
51
|
+
"audio/x-wav",
|
|
52
|
+
"video/3gpp",
|
|
53
|
+
"video/mp2t",
|
|
54
|
+
"video/mpeg",
|
|
55
|
+
"video/ogg",
|
|
56
|
+
"video/quicktime",
|
|
57
|
+
"video/webm",
|
|
58
|
+
"video/x-msvideo",
|
|
59
|
+
"application/java-archive",
|
|
60
|
+
"application/vnd.apple.installer+xml",
|
|
61
|
+
"application/x-7z-compressed",
|
|
62
|
+
"application/x-apple-diskimage",
|
|
63
|
+
"application/x-bzip",
|
|
64
|
+
"application/x-bzip2",
|
|
65
|
+
"application/x-gzip",
|
|
66
|
+
"application/x-java-archive",
|
|
67
|
+
"application/x-rar-compressed",
|
|
68
|
+
"application/x-tar",
|
|
69
|
+
"application/x-zip",
|
|
70
|
+
"application/zip"
|
|
79
71
|
];
|
|
80
72
|
function isBinaryType(contentType) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
if (!contentType) return false;
|
|
74
|
+
const [test] = contentType.split(";");
|
|
75
|
+
return binaryTypes.includes(test);
|
|
84
76
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/adapters/host.ts
|
|
79
|
+
/**
|
|
80
|
+
* Resolves the host used to build the `Request` URL from a raw host value
|
|
81
|
+
* (e.g. an `x-forwarded-host`/`host` header or an API Gateway domain name).
|
|
82
|
+
*
|
|
83
|
+
* React Router derives the host for its built-in cross-origin (CSRF) check on
|
|
84
|
+
* action requests from `new URL(request.url).host`, so the host constructed
|
|
85
|
+
* here must be trustworthy and well-formed. Invalid characters are stripped and
|
|
86
|
+
* the port is validated to avoid constructing a malformed URL (or leaking a
|
|
87
|
+
* spoofed host) from a garbled header value.
|
|
88
|
+
*
|
|
89
|
+
* Mirrors the hardening done by the upstream `@react-router/architect` adapter.
|
|
90
|
+
*/
|
|
91
|
+
function resolveHost(rawHost) {
|
|
92
|
+
const [rawHostname = "", portStr] = (rawHost ?? "").split(":");
|
|
93
|
+
const hostname = rawHostname.split(/[\\/?#@]/)[0] || "localhost";
|
|
94
|
+
const hostPort = Number.parseInt(portStr ?? "", 10);
|
|
95
|
+
const port = Number.isSafeInteger(hostPort) ? hostPort : void 0;
|
|
96
|
+
return `${hostname}${port ? `:${port}` : ""}`;
|
|
100
97
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/adapters/api-gateway-v1.ts
|
|
100
|
+
function createReactRouterRequestAPIGatewayV1(event, getHost) {
|
|
101
|
+
const host = resolveHost(getHost?.(event) ?? (event.headers["x-forwarded-host"] || event.headers.Host));
|
|
102
|
+
const scheme = event.headers["x-forwarded-proto"] || "http";
|
|
103
|
+
const rawQueryString = new URLSearchParams(event.queryStringParameters).toString();
|
|
104
|
+
const search = rawQueryString.length > 0 ? `?${rawQueryString}` : "";
|
|
105
|
+
const url = new URL(event.path + search, `${scheme}://${host}`);
|
|
106
|
+
const isFormData = event.headers["content-type"]?.includes("multipart/form-data");
|
|
107
|
+
const controller = new AbortController();
|
|
108
|
+
return new Request(url.href, {
|
|
109
|
+
method: event.requestContext.httpMethod,
|
|
110
|
+
headers: createReactRouterHeadersAPIGatewayV1(event.headers),
|
|
111
|
+
signal: controller.signal,
|
|
112
|
+
body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body || void 0
|
|
113
|
+
});
|
|
112
114
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
statusCode: nodeResponse.status,
|
|
120
|
-
headers: Object.fromEntries(nodeResponse.headers.entries()),
|
|
121
|
-
cookies
|
|
122
|
-
};
|
|
115
|
+
function createReactRouterHeadersAPIGatewayV1(requestHeaders) {
|
|
116
|
+
const headers = new Headers();
|
|
117
|
+
for (const [header, value] of Object.entries(requestHeaders)) if (value) headers.append(header, value);
|
|
118
|
+
return headers;
|
|
123
119
|
}
|
|
124
|
-
async function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return result;
|
|
120
|
+
async function sendReactRouterResponseAPIGatewayV1(nodeResponse) {
|
|
121
|
+
const isBase64Encoded = isBinaryType(nodeResponse.headers.get("Content-Type"));
|
|
122
|
+
let body;
|
|
123
|
+
if (nodeResponse.body) if (isBase64Encoded) body = await readableStreamToString(nodeResponse.body, "base64");
|
|
124
|
+
else body = await nodeResponse.text();
|
|
125
|
+
return {
|
|
126
|
+
statusCode: nodeResponse.status,
|
|
127
|
+
headers: Object.fromEntries(nodeResponse.headers.entries()),
|
|
128
|
+
body: body || "",
|
|
129
|
+
isBase64Encoded
|
|
130
|
+
};
|
|
136
131
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
const apiGatewayV1Adapter = {
|
|
133
|
+
wrapHandler: (handler) => (e) => handler(e),
|
|
134
|
+
createReactRouterRequest: createReactRouterRequestAPIGatewayV1,
|
|
135
|
+
sendReactRouterResponse: sendReactRouterResponseAPIGatewayV1
|
|
141
136
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
signal: controller.signal,
|
|
158
|
-
body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body || void 0
|
|
159
|
-
});
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/adapters/api-gateway-v2.ts
|
|
139
|
+
function createReactRouterRequestAPIGateywayV2(event, getHost) {
|
|
140
|
+
const host = resolveHost(getHost?.(event) ?? (event.headers["x-forwarded-host"] || event.headers.host));
|
|
141
|
+
const search = event.rawQueryString.length ? `?${event.rawQueryString}` : "";
|
|
142
|
+
const scheme = event.headers["x-forwarded-proto"] || "http";
|
|
143
|
+
const url = new URL(event.rawPath + search, `${scheme}://${host}`);
|
|
144
|
+
const isFormData = event.headers["content-type"]?.includes("multipart/form-data");
|
|
145
|
+
const controller = new AbortController();
|
|
146
|
+
return new Request(url.href, {
|
|
147
|
+
method: event.requestContext.http.method,
|
|
148
|
+
headers: createReactRouterHeadersAPIGatewayV2(event.headers, event.cookies),
|
|
149
|
+
signal: controller.signal,
|
|
150
|
+
body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body
|
|
151
|
+
});
|
|
160
152
|
}
|
|
161
|
-
function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return headers;
|
|
153
|
+
function createReactRouterHeadersAPIGatewayV2(requestHeaders, requestCookies) {
|
|
154
|
+
const headers = new Headers();
|
|
155
|
+
for (const [header, value] of Object.entries(requestHeaders)) if (value) headers.append(header, value);
|
|
156
|
+
if (requestCookies) headers.append("Cookie", requestCookies.join("; "));
|
|
157
|
+
return headers;
|
|
169
158
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
isBase64Encoded
|
|
186
|
-
};
|
|
159
|
+
function extractAPIGatewayV2ResponseMetadata(nodeResponse) {
|
|
160
|
+
const cookies = nodeResponse.headers.getSetCookie();
|
|
161
|
+
if (cookies.length) nodeResponse.headers.delete("Set-Cookie");
|
|
162
|
+
return {
|
|
163
|
+
statusCode: nodeResponse.status,
|
|
164
|
+
headers: Object.fromEntries(nodeResponse.headers.entries()),
|
|
165
|
+
cookies
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async function sendReactRouterResponseAPIGatewayV2(nodeResponse) {
|
|
169
|
+
const result = extractAPIGatewayV2ResponseMetadata(nodeResponse);
|
|
170
|
+
result.isBase64Encoded = isBinaryType(nodeResponse.headers.get("Content-Type"));
|
|
171
|
+
if (nodeResponse.body) if (result.isBase64Encoded) result.body = await readableStreamToString(nodeResponse.body, "base64");
|
|
172
|
+
else result.body = await nodeResponse.text();
|
|
173
|
+
return result;
|
|
187
174
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
175
|
+
const apiGatewayV2Adapter = {
|
|
176
|
+
wrapHandler: (handler) => (e) => handler(e),
|
|
177
|
+
createReactRouterRequest: createReactRouterRequestAPIGateywayV2,
|
|
178
|
+
sendReactRouterResponse: sendReactRouterResponseAPIGatewayV2
|
|
192
179
|
};
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body || void 0
|
|
211
|
-
});
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/adapters/application-load-balancer.ts
|
|
182
|
+
function createReactRouterRequestALB(event, getHost) {
|
|
183
|
+
const headers = event?.headers || {};
|
|
184
|
+
const host = resolveHost(getHost?.(event) ?? (headers["x-forwarded-host"] || headers.Host));
|
|
185
|
+
const scheme = headers["x-forwarded-proto"] || "http";
|
|
186
|
+
const rawQueryString = new URLSearchParams(event.queryStringParameters).toString();
|
|
187
|
+
const search = rawQueryString.length > 0 ? `?${rawQueryString}` : "";
|
|
188
|
+
const url = new URL(event.path + search, `${scheme}://${host}`);
|
|
189
|
+
const isFormData = headers["content-type"]?.includes("multipart/form-data");
|
|
190
|
+
const controller = new AbortController();
|
|
191
|
+
return new Request(url.href, {
|
|
192
|
+
method: event.httpMethod,
|
|
193
|
+
headers: createReactRouterHeadersALB(headers),
|
|
194
|
+
signal: controller.signal,
|
|
195
|
+
body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body || void 0
|
|
196
|
+
});
|
|
212
197
|
}
|
|
213
198
|
function createReactRouterHeadersALB(requestHeaders) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
headers.append(header, value);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return headers;
|
|
199
|
+
const headers = new Headers();
|
|
200
|
+
for (const [header, value] of Object.entries(requestHeaders)) if (value) headers.append(header, value);
|
|
201
|
+
return headers;
|
|
221
202
|
}
|
|
222
203
|
async function sendReactRouterResponseALB(nodeResponse) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return {
|
|
234
|
-
statusCode: nodeResponse.status,
|
|
235
|
-
headers: Object.fromEntries(nodeResponse.headers.entries()),
|
|
236
|
-
body: body || "",
|
|
237
|
-
isBase64Encoded
|
|
238
|
-
};
|
|
204
|
+
const isBase64Encoded = isBinaryType(nodeResponse.headers.get("Content-Type"));
|
|
205
|
+
let body;
|
|
206
|
+
if (nodeResponse.body) if (isBase64Encoded) body = await readableStreamToString(nodeResponse.body, "base64");
|
|
207
|
+
else body = await nodeResponse.text();
|
|
208
|
+
return {
|
|
209
|
+
statusCode: nodeResponse.status,
|
|
210
|
+
headers: Object.fromEntries(nodeResponse.headers.entries()),
|
|
211
|
+
body: body || "",
|
|
212
|
+
isBase64Encoded
|
|
213
|
+
};
|
|
239
214
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
215
|
+
const applicationLoadBalancerAdapter = {
|
|
216
|
+
wrapHandler: (handler) => (e) => handler(e),
|
|
217
|
+
createReactRouterRequest: createReactRouterRequestALB,
|
|
218
|
+
sendReactRouterResponse: sendReactRouterResponseALB
|
|
244
219
|
};
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (!body) {
|
|
258
|
-
body = emptyStream();
|
|
259
|
-
}
|
|
260
|
-
const httpResponseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
|
|
261
|
-
await writeReadableStreamToWritable(body, httpResponseStream);
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/adapters/function-url-streaming.ts
|
|
222
|
+
const emptyStream = () => new ReadableStream({ start(controller) {
|
|
223
|
+
controller.enqueue("");
|
|
224
|
+
controller.close();
|
|
225
|
+
} });
|
|
226
|
+
const sendReactRouterResponseFunctionUrlStreaming = async (response, responseStream) => {
|
|
227
|
+
const metadata = extractAPIGatewayV2ResponseMetadata(response);
|
|
228
|
+
let body = response.body;
|
|
229
|
+
if (!body) body = emptyStream();
|
|
230
|
+
const httpResponseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
|
|
231
|
+
await writeReadableStreamToWritable(body, httpResponseStream);
|
|
262
232
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
233
|
+
const functionUrlStreamingAdapter = {
|
|
234
|
+
wrapHandler: awslambda.streamifyResponse,
|
|
235
|
+
createReactRouterRequest: createReactRouterRequestAPIGateywayV2,
|
|
236
|
+
sendReactRouterResponse: sendReactRouterResponseFunctionUrlStreaming
|
|
267
237
|
};
|
|
268
|
-
|
|
269
|
-
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/server.ts
|
|
240
|
+
/**
|
|
241
|
+
* Returns a request handler for AWS API Gateway V1
|
|
242
|
+
*
|
|
243
|
+
*/
|
|
244
|
+
/**
|
|
245
|
+
* Returns a request handler for AWS API Gateway V1 events.
|
|
246
|
+
*
|
|
247
|
+
* @param options - The handler options, including the React Router server build,
|
|
248
|
+
* optional getLoadContext function, and mode string.
|
|
249
|
+
* @returns An AWS API Gateway V1 handler compatible with APIGatewayProxyHandler.
|
|
250
|
+
*/
|
|
270
251
|
function createAPIGatewayV1RequestHandler(options) {
|
|
271
|
-
|
|
252
|
+
return createRequestHandlerForAdapter(apiGatewayV1Adapter, options);
|
|
272
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Returns a request handler for AWS API Gateway V2 events.
|
|
256
|
+
*
|
|
257
|
+
* @param options - The handler options, including the React Router server build,
|
|
258
|
+
* optional getLoadContext function, and mode string.
|
|
259
|
+
* @returns An AWS API Gateway V2 handler compatible with APIGatewayProxyHandlerV2.
|
|
260
|
+
*/
|
|
273
261
|
function createAPIGatewayV2RequestHandler(options) {
|
|
274
|
-
|
|
262
|
+
return createRequestHandlerForAdapter(apiGatewayV2Adapter, options);
|
|
275
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Returns a request handler for AWS Application Load Balancer events.
|
|
266
|
+
*
|
|
267
|
+
* @param options - The handler options, including the React Router server build,
|
|
268
|
+
* optional getLoadContext function, and mode string.
|
|
269
|
+
* @returns An AWS ALB handler compatible with ALBHandler.
|
|
270
|
+
*/
|
|
276
271
|
function createALBRequestHandler(options) {
|
|
277
|
-
|
|
272
|
+
return createRequestHandlerForAdapter(applicationLoadBalancerAdapter, options);
|
|
278
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Returns a request handler for AWS Lambda Function URL events (invoke mode BUFFERED).
|
|
276
|
+
*
|
|
277
|
+
* @param options - The handler options, including the React Router server build,
|
|
278
|
+
* optional getLoadContext function, and mode string.
|
|
279
|
+
* @returns An AWS Lambda Function URL handler compatible with Lambda Function URLs with InvokeMode BUFFERED.
|
|
280
|
+
*/
|
|
279
281
|
function createFunctionURLRequestHandler(options) {
|
|
280
|
-
|
|
282
|
+
return createRequestHandlerForAdapter(apiGatewayV2Adapter, options);
|
|
281
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Returns a request handler for AWS Lambda Function URL events (invoke mode RESPONSE_STREAM).
|
|
286
|
+
*
|
|
287
|
+
* @param options - The handler options, including the React Router server build,
|
|
288
|
+
* optional getLoadContext function, and mode string.
|
|
289
|
+
* @returns A streaming AWS Lambda Function URL handler compatible with Lambda Function URLs with InvokeMode RESPONSE_STREAM.
|
|
290
|
+
*/
|
|
282
291
|
function createFunctionURLStreamingRequestHandler(options) {
|
|
283
|
-
|
|
292
|
+
return createRequestHandlerForAdapter(functionUrlStreamingAdapter, options);
|
|
284
293
|
}
|
|
285
|
-
function createRequestHandlerForAdapter(awsAdapter, { build, getLoadContext, mode = process.env.NODE_ENV }) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const response = await handleRequest(request, loadContext);
|
|
299
|
-
return await awsAdapter.sendReactRouterResponse(response, res);
|
|
300
|
-
});
|
|
294
|
+
function createRequestHandlerForAdapter(awsAdapter, { build, getLoadContext, mode = process.env.NODE_ENV, getHost }) {
|
|
295
|
+
const handleRequest = createRequestHandler$1(build, mode);
|
|
296
|
+
return awsAdapter.wrapHandler(async (event, res) => {
|
|
297
|
+
let request;
|
|
298
|
+
try {
|
|
299
|
+
request = awsAdapter.createReactRouterRequest(event, getHost);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
return await awsAdapter.sendReactRouterResponse(new Response(`Bad Request: ${e instanceof Error ? e.message : e}`, { status: 400 }), res);
|
|
302
|
+
}
|
|
303
|
+
const loadContext = await getLoadContext?.(event);
|
|
304
|
+
const response = await handleRequest(request, loadContext);
|
|
305
|
+
return await awsAdapter.sendReactRouterResponse(response, res);
|
|
306
|
+
});
|
|
301
307
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/legacy.ts
|
|
310
|
+
let AWSProxy = /* @__PURE__ */ function(AWSProxy) {
|
|
311
|
+
AWSProxy["APIGatewayV1"] = "APIGatewayV1";
|
|
312
|
+
AWSProxy["APIGatewayV2"] = "APIGatewayV2";
|
|
313
|
+
AWSProxy["ALB"] = "ALB";
|
|
314
|
+
AWSProxy["FunctionURL"] = "FunctionURL";
|
|
315
|
+
AWSProxy["FunctionURLStreaming"] = "FunctionURLStreaming";
|
|
316
|
+
return AWSProxy;
|
|
317
|
+
}({});
|
|
318
|
+
/**
|
|
319
|
+
* Returns a request handler for AWS that serves the response using React Router.
|
|
320
|
+
*
|
|
321
|
+
* @deprecated Use one of the gateway-specific create*RequestHandler methods instead for better tree-shaking.
|
|
322
|
+
* - `createAPIGatewayV1RequestHandler`
|
|
323
|
+
* - `createAPIGatewayV2RequestHandler`
|
|
324
|
+
* - `createALBRequestHandler`
|
|
325
|
+
* - `createFunctionURLRequestHandler`
|
|
326
|
+
* - `createFunctionURLStreamingRequestHandler`
|
|
327
|
+
*/
|
|
312
328
|
function createRequestHandler(options) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
);
|
|
323
|
-
case "ALB" /* ALB */:
|
|
324
|
-
return createALBRequestHandler(opts);
|
|
325
|
-
case "FunctionURL" /* FunctionURL */:
|
|
326
|
-
return createFunctionURLRequestHandler(
|
|
327
|
-
opts
|
|
328
|
-
);
|
|
329
|
-
case "FunctionURLStreaming" /* FunctionURLStreaming */:
|
|
330
|
-
return createFunctionURLStreamingRequestHandler(
|
|
331
|
-
opts
|
|
332
|
-
);
|
|
333
|
-
default:
|
|
334
|
-
return assertNever(awsProxy, `Unsupported buffered AWS Proxy type: ${awsProxy}`);
|
|
335
|
-
}
|
|
329
|
+
const { awsProxy = "APIGatewayV2", ...opts } = options;
|
|
330
|
+
switch (awsProxy) {
|
|
331
|
+
case "APIGatewayV1": return createAPIGatewayV1RequestHandler(opts);
|
|
332
|
+
case "APIGatewayV2": return createAPIGatewayV2RequestHandler(opts);
|
|
333
|
+
case "ALB": return createALBRequestHandler(opts);
|
|
334
|
+
case "FunctionURL": return createFunctionURLRequestHandler(opts);
|
|
335
|
+
case "FunctionURLStreaming": return createFunctionURLStreamingRequestHandler(opts);
|
|
336
|
+
default: return assertNever(awsProxy, `Unsupported buffered AWS Proxy type: ${awsProxy}`);
|
|
337
|
+
}
|
|
336
338
|
}
|
|
337
339
|
function assertNever(_x, message) {
|
|
338
|
-
|
|
340
|
+
throw new Error(message);
|
|
339
341
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
createAPIGatewayV2RequestHandler,
|
|
345
|
-
createFunctionURLRequestHandler,
|
|
346
|
-
createFunctionURLStreamingRequestHandler,
|
|
347
|
-
createRequestHandler
|
|
348
|
-
};
|
|
342
|
+
//#endregion
|
|
343
|
+
export { AWSProxy, createALBRequestHandler, createAPIGatewayV1RequestHandler, createAPIGatewayV2RequestHandler, createFunctionURLRequestHandler, createFunctionURLStreamingRequestHandler, createRequestHandler };
|
|
344
|
+
|
|
345
|
+
//# sourceMappingURL=index.mjs.map
|