@geostrategists/react-router-aws 2.2.1 → 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/dist/index.mjs CHANGED
@@ -1,348 +1,345 @@
1
1
  /**
2
- * @geostrategists/react-router-aws v2.2.1
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.md file in the root directory of this source tree.
7
+ * LICENSE file in the root directory of this source tree.
8
8
  *
9
9
  * @license MIT
10
10
  */
11
-
12
- // src/server.ts
13
- import {
14
- createRequestHandler as createReactRouterRequestHandler
15
- } from "react-router";
16
-
17
- // src/adapters/api-gateway-v2.ts
18
- import { readableStreamToString } from "@react-router/node";
19
-
20
- // src/binaryTypes.ts
21
- var binaryTypes = [
22
- "application/octet-stream",
23
- // Docs
24
- "application/epub+zip",
25
- "application/msword",
26
- "application/pdf",
27
- "application/rtf",
28
- "application/vnd.amazon.ebook",
29
- "application/vnd.ms-excel",
30
- "application/vnd.ms-powerpoint",
31
- "application/vnd.openxmlformats-officedocument.presentationml.presentation",
32
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
33
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
34
- // Fonts
35
- "font/otf",
36
- "font/woff",
37
- "font/woff2",
38
- // Images
39
- "image/avif",
40
- "image/bmp",
41
- "image/gif",
42
- "image/jpeg",
43
- "image/png",
44
- "image/tiff",
45
- "image/vnd.microsoft.icon",
46
- "image/webp",
47
- // Audio
48
- "audio/3gpp",
49
- "audio/aac",
50
- "audio/basic",
51
- "audio/mpeg",
52
- "audio/ogg",
53
- "audio/wav",
54
- "audio/webm",
55
- "audio/x-aiff",
56
- "audio/x-midi",
57
- "audio/x-wav",
58
- // Video
59
- "video/3gpp",
60
- "video/mp2t",
61
- "video/mpeg",
62
- "video/ogg",
63
- "video/quicktime",
64
- "video/webm",
65
- "video/x-msvideo",
66
- // Archives
67
- "application/java-archive",
68
- "application/vnd.apple.installer+xml",
69
- "application/x-7z-compressed",
70
- "application/x-apple-diskimage",
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
- if (!contentType) return false;
82
- const [test] = contentType.split(";");
83
- return binaryTypes.includes(test);
73
+ if (!contentType) return false;
74
+ const [test] = contentType.split(";");
75
+ return binaryTypes.includes(test);
84
76
  }
85
-
86
- // src/adapters/api-gateway-v2.ts
87
- function createReactRouterRequestAPIGateywayV2(event) {
88
- const host = event.headers["x-forwarded-host"] || event.headers.host;
89
- const search = event.rawQueryString.length ? `?${event.rawQueryString}` : "";
90
- const scheme = event.headers["x-forwarded-proto"] || "http";
91
- const url = new URL(event.rawPath + search, `${scheme}://${host}`);
92
- const isFormData = event.headers["content-type"]?.includes("multipart/form-data");
93
- const controller = new AbortController();
94
- return new Request(url.href, {
95
- method: event.requestContext.http.method,
96
- headers: createReactRouterHeadersAPIGatewayV2(event.headers, event.cookies),
97
- signal: controller.signal,
98
- body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body
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
- function createReactRouterHeadersAPIGatewayV2(requestHeaders, requestCookies) {
102
- const headers = new Headers();
103
- for (const [header, value] of Object.entries(requestHeaders)) {
104
- if (value) {
105
- headers.append(header, value);
106
- }
107
- }
108
- if (requestCookies) {
109
- headers.append("Cookie", requestCookies.join("; "));
110
- }
111
- return headers;
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 extractAPIGatewayV2ResponseMetadata(nodeResponse) {
114
- const cookies = nodeResponse.headers.getSetCookie();
115
- if (cookies.length) {
116
- nodeResponse.headers.delete("Set-Cookie");
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 sendReactRouterResponseAPIGatewayV2(nodeResponse) {
125
- const result = extractAPIGatewayV2ResponseMetadata(nodeResponse);
126
- const contentType = nodeResponse.headers.get("Content-Type");
127
- result.isBase64Encoded = isBinaryType(contentType);
128
- if (nodeResponse.body) {
129
- if (result.isBase64Encoded) {
130
- result.body = await readableStreamToString(nodeResponse.body, "base64");
131
- } else {
132
- result.body = await nodeResponse.text();
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
- var apiGatewayV2Adapter = {
138
- wrapHandler: (handler) => (e) => handler(e),
139
- createReactRouterRequest: createReactRouterRequestAPIGateywayV2,
140
- sendReactRouterResponse: sendReactRouterResponseAPIGatewayV2
132
+ const apiGatewayV1Adapter = {
133
+ wrapHandler: (handler) => (e) => handler(e),
134
+ createReactRouterRequest: createReactRouterRequestAPIGatewayV1,
135
+ sendReactRouterResponse: sendReactRouterResponseAPIGatewayV1
141
136
  };
142
-
143
- // src/adapters/api-gateway-v1.ts
144
- import { readableStreamToString as readableStreamToString2 } from "@react-router/node";
145
- import { URLSearchParams } from "url";
146
- function createReactRouterRequestAPIGatewayV1(event) {
147
- const host = event.headers["x-forwarded-host"] || event.headers.Host;
148
- const scheme = event.headers["x-forwarded-proto"] || "http";
149
- const rawQueryString = new URLSearchParams(event.queryStringParameters).toString();
150
- const search = rawQueryString.length > 0 ? `?${rawQueryString}` : "";
151
- const url = new URL(event.path + search, `${scheme}://${host}`);
152
- const isFormData = event.headers["content-type"]?.includes("multipart/form-data");
153
- const controller = new AbortController();
154
- return new Request(url.href, {
155
- method: event.requestContext.httpMethod,
156
- headers: createReactRouterHeadersAPIGatewayV1(event.headers),
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 createReactRouterHeadersAPIGatewayV1(requestHeaders) {
162
- const headers = new Headers();
163
- for (const [header, value] of Object.entries(requestHeaders)) {
164
- if (value) {
165
- headers.append(header, value);
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
- async function sendReactRouterResponseAPIGatewayV1(nodeResponse) {
171
- const contentType = nodeResponse.headers.get("Content-Type");
172
- const isBase64Encoded = isBinaryType(contentType);
173
- let body;
174
- if (nodeResponse.body) {
175
- if (isBase64Encoded) {
176
- body = await readableStreamToString2(nodeResponse.body, "base64");
177
- } else {
178
- body = await nodeResponse.text();
179
- }
180
- }
181
- return {
182
- statusCode: nodeResponse.status,
183
- headers: Object.fromEntries(nodeResponse.headers.entries()),
184
- body: body || "",
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
- var apiGatewayV1Adapter = {
189
- wrapHandler: (handler) => (e) => handler(e),
190
- createReactRouterRequest: createReactRouterRequestAPIGatewayV1,
191
- sendReactRouterResponse: sendReactRouterResponseAPIGatewayV1
175
+ const apiGatewayV2Adapter = {
176
+ wrapHandler: (handler) => (e) => handler(e),
177
+ createReactRouterRequest: createReactRouterRequestAPIGateywayV2,
178
+ sendReactRouterResponse: sendReactRouterResponseAPIGatewayV2
192
179
  };
193
-
194
- // src/adapters/application-load-balancer.ts
195
- import { readableStreamToString as readableStreamToString3 } from "@react-router/node";
196
- import { URLSearchParams as URLSearchParams2 } from "url";
197
- function createReactRouterRequestALB(event) {
198
- const headers = event?.headers || {};
199
- const host = headers["x-forwarded-host"] || headers.Host;
200
- const scheme = headers["x-forwarded-proto"] || "http";
201
- const rawQueryString = new URLSearchParams2(event.queryStringParameters).toString();
202
- const search = rawQueryString.length > 0 ? `?${rawQueryString}` : "";
203
- const url = new URL(event.path + search, `${scheme}://${host}`);
204
- const isFormData = headers["content-type"]?.includes("multipart/form-data");
205
- const controller = new AbortController();
206
- return new Request(url.href, {
207
- method: event.httpMethod,
208
- headers: createReactRouterHeadersALB(headers),
209
- signal: controller.signal,
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
- const headers = new Headers();
215
- for (const [header, value] of Object.entries(requestHeaders)) {
216
- if (value) {
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
- const contentType = nodeResponse.headers.get("Content-Type");
224
- const isBase64Encoded = isBinaryType(contentType);
225
- let body;
226
- if (nodeResponse.body) {
227
- if (isBase64Encoded) {
228
- body = await readableStreamToString3(nodeResponse.body, "base64");
229
- } else {
230
- body = await nodeResponse.text();
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
- var applicationLoadBalancerAdapter = {
241
- wrapHandler: (handler) => (e) => handler(e),
242
- createReactRouterRequest: createReactRouterRequestALB,
243
- sendReactRouterResponse: sendReactRouterResponseALB
215
+ const applicationLoadBalancerAdapter = {
216
+ wrapHandler: (handler) => (e) => handler(e),
217
+ createReactRouterRequest: createReactRouterRequestALB,
218
+ sendReactRouterResponse: sendReactRouterResponseALB
244
219
  };
245
-
246
- // src/adapters/function-url-streaming.ts
247
- import { writeReadableStreamToWritable } from "@react-router/node";
248
- var emptyStream = () => new ReadableStream({
249
- start(controller) {
250
- controller.enqueue("");
251
- controller.close();
252
- }
253
- });
254
- var sendReactRouterResponseFunctionUrlStreaming = async (response, responseStream) => {
255
- const metadata = extractAPIGatewayV2ResponseMetadata(response);
256
- let body = response.body;
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
- var functionUrlStreamingAdapter = {
264
- wrapHandler: awslambda.streamifyResponse,
265
- createReactRouterRequest: createReactRouterRequestAPIGateywayV2,
266
- sendReactRouterResponse: sendReactRouterResponseFunctionUrlStreaming
233
+ const functionUrlStreamingAdapter = {
234
+ wrapHandler: awslambda.streamifyResponse,
235
+ createReactRouterRequest: createReactRouterRequestAPIGateywayV2,
236
+ sendReactRouterResponse: sendReactRouterResponseFunctionUrlStreaming
267
237
  };
268
-
269
- // src/server.ts
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
- return createRequestHandlerForAdapter(apiGatewayV1Adapter, options);
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
- return createRequestHandlerForAdapter(apiGatewayV2Adapter, options);
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
- return createRequestHandlerForAdapter(applicationLoadBalancerAdapter, options);
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
- return createRequestHandlerForAdapter(apiGatewayV2Adapter, options);
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
- return createRequestHandlerForAdapter(functionUrlStreamingAdapter, options);
292
+ return createRequestHandlerForAdapter(functionUrlStreamingAdapter, options);
284
293
  }
285
- function createRequestHandlerForAdapter(awsAdapter, { build, getLoadContext, mode = process.env.NODE_ENV }) {
286
- const handleRequest = createReactRouterRequestHandler(build, mode);
287
- return awsAdapter.wrapHandler(async (event, res) => {
288
- let request;
289
- try {
290
- request = awsAdapter.createReactRouterRequest(event);
291
- } catch (e) {
292
- return await awsAdapter.sendReactRouterResponse(
293
- new Response(`Bad Request: ${e instanceof Error ? e.message : e}`, { status: 400 }),
294
- res
295
- );
296
- }
297
- const loadContext = await getLoadContext?.(event);
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
- // src/legacy.ts
304
- var AWSProxy = /* @__PURE__ */ ((AWSProxy2) => {
305
- AWSProxy2["APIGatewayV1"] = "APIGatewayV1";
306
- AWSProxy2["APIGatewayV2"] = "APIGatewayV2";
307
- AWSProxy2["ALB"] = "ALB";
308
- AWSProxy2["FunctionURL"] = "FunctionURL";
309
- AWSProxy2["FunctionURLStreaming"] = "FunctionURLStreaming";
310
- return AWSProxy2;
311
- })(AWSProxy || {});
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
- const { awsProxy = "APIGatewayV2" /* APIGatewayV2 */, ...opts } = options;
314
- switch (awsProxy) {
315
- case "APIGatewayV1" /* APIGatewayV1 */:
316
- return createAPIGatewayV1RequestHandler(
317
- opts
318
- );
319
- case "APIGatewayV2" /* APIGatewayV2 */:
320
- return createAPIGatewayV2RequestHandler(
321
- opts
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
- throw new Error(message);
340
+ throw new Error(message);
339
341
  }
340
- export {
341
- AWSProxy,
342
- createALBRequestHandler,
343
- createAPIGatewayV1RequestHandler,
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