@openhi/constructs 0.0.115 → 0.0.116
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/lib/index.d.mts +267 -8
- package/lib/index.d.ts +282 -9
- package/lib/index.js +408 -123
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +417 -123
- package/lib/index.mjs.map +1 -1
- package/lib/static-hosting.viewer-request-handler.d.mts +54 -0
- package/lib/static-hosting.viewer-request-handler.d.ts +54 -0
- package/lib/static-hosting.viewer-request-handler.js +79 -0
- package/lib/static-hosting.viewer-request-handler.js.map +1 -0
- package/lib/static-hosting.viewer-request-handler.mjs +53 -0
- package/lib/static-hosting.viewer-request-handler.mjs.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CloudFrontRequest, CloudFrontRequestEvent } from 'aws-lambda';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see sites/www-docs/content/packages/@openhi/constructs/components/static-hosting/static-hosting.viewer-request-handler.md
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Hosting mode controls how path-like URIs get a default document.
|
|
8
|
+
*
|
|
9
|
+
* - `spa`: path-like URIs (e.g. `/dashboard`, `/patients/123`) rewrite to
|
|
10
|
+
* `/index.html` so the single-page app's root index is served and the
|
|
11
|
+
* client-side router handles the path.
|
|
12
|
+
* - `static`: path-like URIs append `/index.html` (e.g. `/docs` becomes
|
|
13
|
+
* `/docs/index.html`) so multi-page static sites can serve distinct
|
|
14
|
+
* HTML per path.
|
|
15
|
+
*/
|
|
16
|
+
type HostingMode = "spa" | "static";
|
|
17
|
+
/**
|
|
18
|
+
* Viewer Request Handler for SPA mode.
|
|
19
|
+
*
|
|
20
|
+
* - Logs the request
|
|
21
|
+
* - Rewrites path-like URIs to `/index.html`
|
|
22
|
+
* - Prepends the Host header as a folder for multi-tenant routing
|
|
23
|
+
*/
|
|
24
|
+
declare const spaHandler: (event: CloudFrontRequestEvent) => Promise<CloudFrontRequest>;
|
|
25
|
+
/**
|
|
26
|
+
* Viewer Request Handler for static (non-SPA) mode.
|
|
27
|
+
*
|
|
28
|
+
* - Logs the request
|
|
29
|
+
* - Rewrites path-like URIs to `<path>/index.html`
|
|
30
|
+
* - Prepends the Host header as a folder for multi-tenant routing
|
|
31
|
+
*/
|
|
32
|
+
declare const staticHandler: (event: CloudFrontRequestEvent) => Promise<CloudFrontRequest>;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a default document to the request URI based on the hosting mode.
|
|
35
|
+
*
|
|
36
|
+
* In both modes:
|
|
37
|
+
* - `/` and `/index.html` become `/index.html`
|
|
38
|
+
* - URIs whose last segment contains a dot are treated as static files and
|
|
39
|
+
* left unchanged.
|
|
40
|
+
*
|
|
41
|
+
* In `spa` mode, all other path-like URIs rewrite to `/index.html`.
|
|
42
|
+
* In `static` mode, path-like URIs append `/index.html` (trailing slash
|
|
43
|
+
* preserved as a single slash): `/docs` and `/docs/` both become
|
|
44
|
+
* `/docs/index.html`.
|
|
45
|
+
*/
|
|
46
|
+
declare const addDefaultDocument: (request: CloudFrontRequest, mode: HostingMode) => CloudFrontRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Prepends the Host header as a folder to the request URI. Used for
|
|
49
|
+
* multi-tenant routing where each domain maps to a folder in the S3
|
|
50
|
+
* bucket (e.g. `example.com/foo` -> `/example.com/foo`).
|
|
51
|
+
*/
|
|
52
|
+
declare const addDomainFolder: (request: CloudFrontRequest) => CloudFrontRequest;
|
|
53
|
+
|
|
54
|
+
export { type HostingMode, addDefaultDocument, addDomainFolder, spaHandler, staticHandler };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CloudFrontRequest, CloudFrontRequestEvent } from 'aws-lambda';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see sites/www-docs/content/packages/@openhi/constructs/components/static-hosting/static-hosting.viewer-request-handler.md
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Hosting mode controls how path-like URIs get a default document.
|
|
8
|
+
*
|
|
9
|
+
* - `spa`: path-like URIs (e.g. `/dashboard`, `/patients/123`) rewrite to
|
|
10
|
+
* `/index.html` so the single-page app's root index is served and the
|
|
11
|
+
* client-side router handles the path.
|
|
12
|
+
* - `static`: path-like URIs append `/index.html` (e.g. `/docs` becomes
|
|
13
|
+
* `/docs/index.html`) so multi-page static sites can serve distinct
|
|
14
|
+
* HTML per path.
|
|
15
|
+
*/
|
|
16
|
+
type HostingMode = "spa" | "static";
|
|
17
|
+
/**
|
|
18
|
+
* Viewer Request Handler for SPA mode.
|
|
19
|
+
*
|
|
20
|
+
* - Logs the request
|
|
21
|
+
* - Rewrites path-like URIs to `/index.html`
|
|
22
|
+
* - Prepends the Host header as a folder for multi-tenant routing
|
|
23
|
+
*/
|
|
24
|
+
declare const spaHandler: (event: CloudFrontRequestEvent) => Promise<CloudFrontRequest>;
|
|
25
|
+
/**
|
|
26
|
+
* Viewer Request Handler for static (non-SPA) mode.
|
|
27
|
+
*
|
|
28
|
+
* - Logs the request
|
|
29
|
+
* - Rewrites path-like URIs to `<path>/index.html`
|
|
30
|
+
* - Prepends the Host header as a folder for multi-tenant routing
|
|
31
|
+
*/
|
|
32
|
+
declare const staticHandler: (event: CloudFrontRequestEvent) => Promise<CloudFrontRequest>;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a default document to the request URI based on the hosting mode.
|
|
35
|
+
*
|
|
36
|
+
* In both modes:
|
|
37
|
+
* - `/` and `/index.html` become `/index.html`
|
|
38
|
+
* - URIs whose last segment contains a dot are treated as static files and
|
|
39
|
+
* left unchanged.
|
|
40
|
+
*
|
|
41
|
+
* In `spa` mode, all other path-like URIs rewrite to `/index.html`.
|
|
42
|
+
* In `static` mode, path-like URIs append `/index.html` (trailing slash
|
|
43
|
+
* preserved as a single slash): `/docs` and `/docs/` both become
|
|
44
|
+
* `/docs/index.html`.
|
|
45
|
+
*/
|
|
46
|
+
declare const addDefaultDocument: (request: CloudFrontRequest, mode: HostingMode) => CloudFrontRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Prepends the Host header as a folder to the request URI. Used for
|
|
49
|
+
* multi-tenant routing where each domain maps to a folder in the S3
|
|
50
|
+
* bucket (e.g. `example.com/foo` -> `/example.com/foo`).
|
|
51
|
+
*/
|
|
52
|
+
declare const addDomainFolder: (request: CloudFrontRequest) => CloudFrontRequest;
|
|
53
|
+
|
|
54
|
+
export { type HostingMode, addDefaultDocument, addDomainFolder, spaHandler, staticHandler };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/static-hosting/static-hosting.viewer-request-handler.ts
|
|
21
|
+
var static_hosting_viewer_request_handler_exports = {};
|
|
22
|
+
__export(static_hosting_viewer_request_handler_exports, {
|
|
23
|
+
addDefaultDocument: () => addDefaultDocument,
|
|
24
|
+
addDomainFolder: () => addDomainFolder,
|
|
25
|
+
spaHandler: () => spaHandler,
|
|
26
|
+
staticHandler: () => staticHandler
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(static_hosting_viewer_request_handler_exports);
|
|
29
|
+
var isTestEnv = process.env.JEST_WORKER_ID !== void 0;
|
|
30
|
+
var spaHandler = async (event) => {
|
|
31
|
+
return runHandler(event, "spa");
|
|
32
|
+
};
|
|
33
|
+
var staticHandler = async (event) => {
|
|
34
|
+
return runHandler(event, "static");
|
|
35
|
+
};
|
|
36
|
+
var runHandler = async (event, mode) => {
|
|
37
|
+
if (!isTestEnv) {
|
|
38
|
+
console.log("Request Event: ", JSON.stringify(event, null, 2));
|
|
39
|
+
}
|
|
40
|
+
let request = event.Records[0].cf.request;
|
|
41
|
+
request = addDefaultDocument(request, mode);
|
|
42
|
+
request = addDomainFolder(request);
|
|
43
|
+
if (!isTestEnv) {
|
|
44
|
+
console.log("Resulting Request: ", JSON.stringify(request, null, 2));
|
|
45
|
+
}
|
|
46
|
+
return request;
|
|
47
|
+
};
|
|
48
|
+
var addDefaultDocument = (request, mode) => {
|
|
49
|
+
if (request.uri === "/" || request.uri === "/index.html") {
|
|
50
|
+
request.uri = "/index.html";
|
|
51
|
+
return request;
|
|
52
|
+
}
|
|
53
|
+
const segments = request.uri.split("/").filter(Boolean);
|
|
54
|
+
const lastSegment = segments[segments.length - 1] ?? "";
|
|
55
|
+
const looksLikeStaticFile = lastSegment.includes(".");
|
|
56
|
+
if (looksLikeStaticFile) {
|
|
57
|
+
return request;
|
|
58
|
+
}
|
|
59
|
+
if (mode === "spa") {
|
|
60
|
+
request.uri = "/index.html";
|
|
61
|
+
return request;
|
|
62
|
+
}
|
|
63
|
+
const normalized = request.uri.endsWith("/") ? request.uri.slice(0, -1) : request.uri;
|
|
64
|
+
request.uri = `${normalized}/index.html`;
|
|
65
|
+
return request;
|
|
66
|
+
};
|
|
67
|
+
var addDomainFolder = (request) => {
|
|
68
|
+
const hostHeader = request.headers.host[0].value;
|
|
69
|
+
request.uri = `/${hostHeader}${request.uri}`;
|
|
70
|
+
return request;
|
|
71
|
+
};
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
addDefaultDocument,
|
|
75
|
+
addDomainFolder,
|
|
76
|
+
spaHandler,
|
|
77
|
+
staticHandler
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=static-hosting.viewer-request-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/static-hosting/static-hosting.viewer-request-handler.ts"],"sourcesContent":["import { CloudFrontRequest, CloudFrontRequestEvent } from \"aws-lambda\";\n\n/**\n * @see sites/www-docs/content/packages/@openhi/constructs/components/static-hosting/static-hosting.viewer-request-handler.md\n */\n\n/**\n * Hosting mode controls how path-like URIs get a default document.\n *\n * - `spa`: path-like URIs (e.g. `/dashboard`, `/patients/123`) rewrite to\n * `/index.html` so the single-page app's root index is served and the\n * client-side router handles the path.\n * - `static`: path-like URIs append `/index.html` (e.g. `/docs` becomes\n * `/docs/index.html`) so multi-page static sites can serve distinct\n * HTML per path.\n */\nexport type HostingMode = \"spa\" | \"static\";\n\nconst isTestEnv = process.env.JEST_WORKER_ID !== undefined;\n\n/**\n * Viewer Request Handler for SPA mode.\n *\n * - Logs the request\n * - Rewrites path-like URIs to `/index.html`\n * - Prepends the Host header as a folder for multi-tenant routing\n */\nexport const spaHandler = async (\n event: CloudFrontRequestEvent,\n): Promise<CloudFrontRequest> => {\n return runHandler(event, \"spa\");\n};\n\n/**\n * Viewer Request Handler for static (non-SPA) mode.\n *\n * - Logs the request\n * - Rewrites path-like URIs to `<path>/index.html`\n * - Prepends the Host header as a folder for multi-tenant routing\n */\nexport const staticHandler = async (\n event: CloudFrontRequestEvent,\n): Promise<CloudFrontRequest> => {\n return runHandler(event, \"static\");\n};\n\nconst runHandler = async (\n event: CloudFrontRequestEvent,\n mode: HostingMode,\n): Promise<CloudFrontRequest> => {\n if (!isTestEnv) {\n console.log(\"Request Event: \", JSON.stringify(event, null, 2));\n }\n\n let request = event.Records[0].cf.request;\n\n // add index if needed\n request = addDefaultDocument(request, mode);\n\n // prepend folder with domain\n request = addDomainFolder(request);\n\n if (!isTestEnv) {\n console.log(\"Resulting Request: \", JSON.stringify(request, null, 2));\n }\n\n return request;\n};\n\n/**\n * Adds a default document to the request URI based on the hosting mode.\n *\n * In both modes:\n * - `/` and `/index.html` become `/index.html`\n * - URIs whose last segment contains a dot are treated as static files and\n * left unchanged.\n *\n * In `spa` mode, all other path-like URIs rewrite to `/index.html`.\n * In `static` mode, path-like URIs append `/index.html` (trailing slash\n * preserved as a single slash): `/docs` and `/docs/` both become\n * `/docs/index.html`.\n */\nexport const addDefaultDocument = (\n request: CloudFrontRequest,\n mode: HostingMode,\n) => {\n if (request.uri === \"/\" || request.uri === \"/index.html\") {\n request.uri = \"/index.html\";\n return request;\n }\n\n const segments = request.uri.split(\"/\").filter(Boolean);\n const lastSegment = segments[segments.length - 1] ?? \"\";\n const looksLikeStaticFile = lastSegment.includes(\".\");\n\n if (looksLikeStaticFile) {\n return request;\n }\n\n if (mode === \"spa\") {\n request.uri = \"/index.html\";\n return request;\n }\n\n // static mode: append /index.html to the path, collapsing any trailing slash\n const normalized = request.uri.endsWith(\"/\")\n ? request.uri.slice(0, -1)\n : request.uri;\n request.uri = `${normalized}/index.html`;\n return request;\n};\n\n/**\n * Prepends the Host header as a folder to the request URI. Used for\n * multi-tenant routing where each domain maps to a folder in the S3\n * bucket (e.g. `example.com/foo` -> `/example.com/foo`).\n */\nexport const addDomainFolder = (request: CloudFrontRequest) => {\n const hostHeader = request.headers.host[0].value;\n request.uri = `/${hostHeader}${request.uri}`;\n return request;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,IAAM,YAAY,QAAQ,IAAI,mBAAmB;AAS1C,IAAM,aAAa,OACxB,UAC+B;AAC/B,SAAO,WAAW,OAAO,KAAK;AAChC;AASO,IAAM,gBAAgB,OAC3B,UAC+B;AAC/B,SAAO,WAAW,OAAO,QAAQ;AACnC;AAEA,IAAM,aAAa,OACjB,OACA,SAC+B;AAC/B,MAAI,CAAC,WAAW;AACd,YAAQ,IAAI,mBAAmB,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAAA,EAC/D;AAEA,MAAI,UAAU,MAAM,QAAQ,CAAC,EAAE,GAAG;AAGlC,YAAU,mBAAmB,SAAS,IAAI;AAG1C,YAAU,gBAAgB,OAAO;AAEjC,MAAI,CAAC,WAAW;AACd,YAAQ,IAAI,uBAAuB,KAAK,UAAU,SAAS,MAAM,CAAC,CAAC;AAAA,EACrE;AAEA,SAAO;AACT;AAeO,IAAM,qBAAqB,CAChC,SACA,SACG;AACH,MAAI,QAAQ,QAAQ,OAAO,QAAQ,QAAQ,eAAe;AACxD,YAAQ,MAAM;AACd,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,QAAQ,IAAI,MAAM,GAAG,EAAE,OAAO,OAAO;AACtD,QAAM,cAAc,SAAS,SAAS,SAAS,CAAC,KAAK;AACrD,QAAM,sBAAsB,YAAY,SAAS,GAAG;AAEpD,MAAI,qBAAqB;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,OAAO;AAClB,YAAQ,MAAM;AACd,WAAO;AAAA,EACT;AAGA,QAAM,aAAa,QAAQ,IAAI,SAAS,GAAG,IACvC,QAAQ,IAAI,MAAM,GAAG,EAAE,IACvB,QAAQ;AACZ,UAAQ,MAAM,GAAG,UAAU;AAC3B,SAAO;AACT;AAOO,IAAM,kBAAkB,CAAC,YAA+B;AAC7D,QAAM,aAAa,QAAQ,QAAQ,KAAK,CAAC,EAAE;AAC3C,UAAQ,MAAM,IAAI,UAAU,GAAG,QAAQ,GAAG;AAC1C,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "./chunk-LZOMFHX3.mjs";
|
|
2
|
+
|
|
3
|
+
// src/components/static-hosting/static-hosting.viewer-request-handler.ts
|
|
4
|
+
var isTestEnv = process.env.JEST_WORKER_ID !== void 0;
|
|
5
|
+
var spaHandler = async (event) => {
|
|
6
|
+
return runHandler(event, "spa");
|
|
7
|
+
};
|
|
8
|
+
var staticHandler = async (event) => {
|
|
9
|
+
return runHandler(event, "static");
|
|
10
|
+
};
|
|
11
|
+
var runHandler = async (event, mode) => {
|
|
12
|
+
if (!isTestEnv) {
|
|
13
|
+
console.log("Request Event: ", JSON.stringify(event, null, 2));
|
|
14
|
+
}
|
|
15
|
+
let request = event.Records[0].cf.request;
|
|
16
|
+
request = addDefaultDocument(request, mode);
|
|
17
|
+
request = addDomainFolder(request);
|
|
18
|
+
if (!isTestEnv) {
|
|
19
|
+
console.log("Resulting Request: ", JSON.stringify(request, null, 2));
|
|
20
|
+
}
|
|
21
|
+
return request;
|
|
22
|
+
};
|
|
23
|
+
var addDefaultDocument = (request, mode) => {
|
|
24
|
+
if (request.uri === "/" || request.uri === "/index.html") {
|
|
25
|
+
request.uri = "/index.html";
|
|
26
|
+
return request;
|
|
27
|
+
}
|
|
28
|
+
const segments = request.uri.split("/").filter(Boolean);
|
|
29
|
+
const lastSegment = segments[segments.length - 1] ?? "";
|
|
30
|
+
const looksLikeStaticFile = lastSegment.includes(".");
|
|
31
|
+
if (looksLikeStaticFile) {
|
|
32
|
+
return request;
|
|
33
|
+
}
|
|
34
|
+
if (mode === "spa") {
|
|
35
|
+
request.uri = "/index.html";
|
|
36
|
+
return request;
|
|
37
|
+
}
|
|
38
|
+
const normalized = request.uri.endsWith("/") ? request.uri.slice(0, -1) : request.uri;
|
|
39
|
+
request.uri = `${normalized}/index.html`;
|
|
40
|
+
return request;
|
|
41
|
+
};
|
|
42
|
+
var addDomainFolder = (request) => {
|
|
43
|
+
const hostHeader = request.headers.host[0].value;
|
|
44
|
+
request.uri = `/${hostHeader}${request.uri}`;
|
|
45
|
+
return request;
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
addDefaultDocument,
|
|
49
|
+
addDomainFolder,
|
|
50
|
+
spaHandler,
|
|
51
|
+
staticHandler
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=static-hosting.viewer-request-handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/static-hosting/static-hosting.viewer-request-handler.ts"],"sourcesContent":["import { CloudFrontRequest, CloudFrontRequestEvent } from \"aws-lambda\";\n\n/**\n * @see sites/www-docs/content/packages/@openhi/constructs/components/static-hosting/static-hosting.viewer-request-handler.md\n */\n\n/**\n * Hosting mode controls how path-like URIs get a default document.\n *\n * - `spa`: path-like URIs (e.g. `/dashboard`, `/patients/123`) rewrite to\n * `/index.html` so the single-page app's root index is served and the\n * client-side router handles the path.\n * - `static`: path-like URIs append `/index.html` (e.g. `/docs` becomes\n * `/docs/index.html`) so multi-page static sites can serve distinct\n * HTML per path.\n */\nexport type HostingMode = \"spa\" | \"static\";\n\nconst isTestEnv = process.env.JEST_WORKER_ID !== undefined;\n\n/**\n * Viewer Request Handler for SPA mode.\n *\n * - Logs the request\n * - Rewrites path-like URIs to `/index.html`\n * - Prepends the Host header as a folder for multi-tenant routing\n */\nexport const spaHandler = async (\n event: CloudFrontRequestEvent,\n): Promise<CloudFrontRequest> => {\n return runHandler(event, \"spa\");\n};\n\n/**\n * Viewer Request Handler for static (non-SPA) mode.\n *\n * - Logs the request\n * - Rewrites path-like URIs to `<path>/index.html`\n * - Prepends the Host header as a folder for multi-tenant routing\n */\nexport const staticHandler = async (\n event: CloudFrontRequestEvent,\n): Promise<CloudFrontRequest> => {\n return runHandler(event, \"static\");\n};\n\nconst runHandler = async (\n event: CloudFrontRequestEvent,\n mode: HostingMode,\n): Promise<CloudFrontRequest> => {\n if (!isTestEnv) {\n console.log(\"Request Event: \", JSON.stringify(event, null, 2));\n }\n\n let request = event.Records[0].cf.request;\n\n // add index if needed\n request = addDefaultDocument(request, mode);\n\n // prepend folder with domain\n request = addDomainFolder(request);\n\n if (!isTestEnv) {\n console.log(\"Resulting Request: \", JSON.stringify(request, null, 2));\n }\n\n return request;\n};\n\n/**\n * Adds a default document to the request URI based on the hosting mode.\n *\n * In both modes:\n * - `/` and `/index.html` become `/index.html`\n * - URIs whose last segment contains a dot are treated as static files and\n * left unchanged.\n *\n * In `spa` mode, all other path-like URIs rewrite to `/index.html`.\n * In `static` mode, path-like URIs append `/index.html` (trailing slash\n * preserved as a single slash): `/docs` and `/docs/` both become\n * `/docs/index.html`.\n */\nexport const addDefaultDocument = (\n request: CloudFrontRequest,\n mode: HostingMode,\n) => {\n if (request.uri === \"/\" || request.uri === \"/index.html\") {\n request.uri = \"/index.html\";\n return request;\n }\n\n const segments = request.uri.split(\"/\").filter(Boolean);\n const lastSegment = segments[segments.length - 1] ?? \"\";\n const looksLikeStaticFile = lastSegment.includes(\".\");\n\n if (looksLikeStaticFile) {\n return request;\n }\n\n if (mode === \"spa\") {\n request.uri = \"/index.html\";\n return request;\n }\n\n // static mode: append /index.html to the path, collapsing any trailing slash\n const normalized = request.uri.endsWith(\"/\")\n ? request.uri.slice(0, -1)\n : request.uri;\n request.uri = `${normalized}/index.html`;\n return request;\n};\n\n/**\n * Prepends the Host header as a folder to the request URI. Used for\n * multi-tenant routing where each domain maps to a folder in the S3\n * bucket (e.g. `example.com/foo` -> `/example.com/foo`).\n */\nexport const addDomainFolder = (request: CloudFrontRequest) => {\n const hostHeader = request.headers.host[0].value;\n request.uri = `/${hostHeader}${request.uri}`;\n return request;\n};\n"],"mappings":";;;AAkBA,IAAM,YAAY,QAAQ,IAAI,mBAAmB;AAS1C,IAAM,aAAa,OACxB,UAC+B;AAC/B,SAAO,WAAW,OAAO,KAAK;AAChC;AASO,IAAM,gBAAgB,OAC3B,UAC+B;AAC/B,SAAO,WAAW,OAAO,QAAQ;AACnC;AAEA,IAAM,aAAa,OACjB,OACA,SAC+B;AAC/B,MAAI,CAAC,WAAW;AACd,YAAQ,IAAI,mBAAmB,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAAA,EAC/D;AAEA,MAAI,UAAU,MAAM,QAAQ,CAAC,EAAE,GAAG;AAGlC,YAAU,mBAAmB,SAAS,IAAI;AAG1C,YAAU,gBAAgB,OAAO;AAEjC,MAAI,CAAC,WAAW;AACd,YAAQ,IAAI,uBAAuB,KAAK,UAAU,SAAS,MAAM,CAAC,CAAC;AAAA,EACrE;AAEA,SAAO;AACT;AAeO,IAAM,qBAAqB,CAChC,SACA,SACG;AACH,MAAI,QAAQ,QAAQ,OAAO,QAAQ,QAAQ,eAAe;AACxD,YAAQ,MAAM;AACd,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,QAAQ,IAAI,MAAM,GAAG,EAAE,OAAO,OAAO;AACtD,QAAM,cAAc,SAAS,SAAS,SAAS,CAAC,KAAK;AACrD,QAAM,sBAAsB,YAAY,SAAS,GAAG;AAEpD,MAAI,qBAAqB;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,OAAO;AAClB,YAAQ,MAAM;AACd,WAAO;AAAA,EACT;AAGA,QAAM,aAAa,QAAQ,IAAI,SAAS,GAAG,IACvC,QAAQ,IAAI,MAAM,GAAG,EAAE,IACvB,QAAQ;AACZ,UAAQ,MAAM,GAAG,UAAU;AAC3B,SAAO;AACT;AAOO,IAAM,kBAAkB,CAAC,YAA+B;AAC7D,QAAM,aAAa,QAAQ,QAAQ,KAAK,CAAC,EAAE;AAC3C,UAAQ,MAAM,IAAI,UAAU,GAAG,QAAQ,GAAG;AAC1C,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"pg": "^8.20.0",
|
|
56
56
|
"type-fest": "^4",
|
|
57
57
|
"ulid": "^3.0.2",
|
|
58
|
-
"@openhi/config": "0.0.0",
|
|
59
58
|
"@openhi/workflows": "0.0.0",
|
|
59
|
+
"@openhi/config": "0.0.0",
|
|
60
60
|
"@openhi/types": "0.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devEngines": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"version": "0.0.
|
|
74
|
+
"version": "0.0.116",
|
|
75
75
|
"types": "lib/index.d.ts",
|
|
76
76
|
"//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"pnpm exec projen\".",
|
|
77
77
|
"scripts": {
|