/** * CloudFront Function injection code ported from SST's Router component. * These are JavaScript code strings that get injected into CloudFront Function handlers. */ /** * Host-based 301 handling injected at the very top of a generated * viewer-request handler (before route matching). Redirects requests whose * `Host` is one of the configured redirect hostnames — and, when * `cloudfrontUrl: false`, requests arriving via the distribution's default * `*.cloudfront.net` domain (the default domain is not knowable inside its * own function config before the distribution exists, but only requests * served via the default domain ever carry a `.cloudfront.net` Host; * alternate domain names never do) — to the canonical hostname with path * and query preserved. * * Relies on `buildHostRedirectResponse` declared by * {@link CF_ROUTER_INJECTION} (function declarations hoist within the * handler). Returns an empty string when there is nothing to redirect. */ export declare const buildHostRedirectInjection: ({ to, hosts, cloudfrontDefault, }: { /** Canonical hostname redirected to. */ to: string | undefined; /** Exact redirect hostnames. */ hosts: string[]; /** Also redirect the distribution's default `*.cloudfront.net` domain. */ cloudfrontDefault: boolean; }) => string; export declare const CF_ROUTER_INJECTION = "\nasync function routeSite(kvNamespace, metadata) {\n if (metadata.redirect && metadata.redirect.hosts.indexOf(event.request.headers.host.value) !== -1) {\n return buildHostRedirectResponse(metadata.redirect.to);\n }\n\n var baselessUri = metadata.base\n ? event.request.uri.replace(metadata.base, \"\")\n : event.request.uri;\n\n try {\n var u = decodeURIComponent(baselessUri);\n var postfixes = u.endsWith(\"/\")\n ? [\"index.html\"]\n : [\"\", \".html\", \"/index.html\"];\n var v = await Promise.any(postfixes.map(function(p) { return cf.kvs().get(kvNamespace + \":\" + u + p).then(function() { return p; }); }));\n event.request.uri = metadata.s3.dir + event.request.uri + v;\n setS3Origin(metadata.s3.domain);\n return;\n } catch (e) {}\n\n if (metadata.s3 && metadata.s3.routes) {\n for (var i=0, l=metadata.s3.routes.length; i 9728;\n }\n\n function buildOversizedHeadersResponse() {\n return {\n statusCode: 431,\n statusDescription: \"Request Header Fields Too Large\",\n headers: { \"cache-control\": { value: \"no-store\" }, \"content-type\": { value: \"text/plain; charset=utf-8\" } },\n body: { encoding: \"text\", data: \"Request headers are too large. Reduce cookie size and try again.\" },\n };\n }\n\n function getRequestHeaderSize() {\n var size = 0;\n for (var key in event.request.headers) {\n var header = event.request.headers[key];\n if (header.multiValue) {\n for (var i=0; i