@ms-cloudpack/app-server 0.7.8 → 0.8.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/lib/createBootstrapRouteHandler.d.ts +9 -0
- package/lib/createBootstrapRouteHandler.d.ts.map +1 -0
- package/lib/createBootstrapRouteHandler.js +50 -0
- package/lib/createBootstrapRouteHandler.js.map +1 -0
- package/lib/createRoutes.d.ts +1 -1
- package/lib/createRoutes.d.ts.map +1 -1
- package/lib/createRoutes.js +17 -4
- package/lib/createRoutes.js.map +1 -1
- package/lib/getCookies.d.ts +6 -0
- package/lib/getCookies.d.ts.map +1 -0
- package/lib/getCookies.js +14 -0
- package/lib/getCookies.js.map +1 -0
- package/lib/inlineScripts/bootstrap.inline.d.ts +2 -0
- package/lib/inlineScripts/bootstrap.inline.d.ts.map +1 -0
- package/lib/inlineScripts/bootstrap.inline.js +33 -0
- package/lib/inlineScripts/bootstrap.inline.js.map +1 -0
- package/lib/inlineScripts/getBrowserCacheRatio.inline.js +6 -2
- package/lib/inlineScripts/getBrowserCacheRatio.inline.js.map +1 -1
- package/lib/inlineScripts/getInlineScripts.d.ts +8 -0
- package/lib/inlineScripts/getInlineScripts.d.ts.map +1 -1
- package/lib/inlineScripts/getInlineScripts.js +24 -4
- package/lib/inlineScripts/getInlineScripts.js.map +1 -1
- package/lib/inlineScripts/getPageLoadTime.inline.js.map +1 -1
- package/lib/renderRoute/renderRoute.d.ts +2 -2
- package/lib/renderRoute/renderRoute.d.ts.map +1 -1
- package/lib/renderRoute/renderRoute.js.map +1 -1
- package/lib/setHeaders.d.ts.map +1 -1
- package/lib/setHeaders.js +5 -6
- package/lib/setHeaders.js.map +1 -1
- package/lib/types/RenderRouteOptions.d.ts +2 -2
- package/lib/types/RenderRouteOptions.d.ts.map +1 -1
- package/lib/types/RenderRouteOptions.js.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from '@ms-cloudpack/api-server';
|
|
2
|
+
import type { Request, Response } from '@ms-cloudpack/create-express-app';
|
|
3
|
+
type CreateBootstrapRouteHandlerContext = Pick<Context, 'packages' | 'packageImportPaths' | 'packageHashes' | 'session'>;
|
|
4
|
+
export declare function createBootstrapRouteHandler(options: {
|
|
5
|
+
definitionName: string;
|
|
6
|
+
exportEntry?: string;
|
|
7
|
+
}, context: CreateBootstrapRouteHandlerContext): (_req: Request, res: Response) => void;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=createBootstrapRouteHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBootstrapRouteHandler.d.ts","sourceRoot":"","sources":["../src/createBootstrapRouteHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAMxD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAsB1E,KAAK,kCAAkC,GAAG,IAAI,CAC5C,OAAO,EACP,UAAU,GAAG,oBAAoB,GAAG,eAAe,GAAG,SAAS,CAChE,CAAC;AAEF,wBAAgB,2BAA2B,CACzC,OAAO,EAAE;IACP,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,EACD,OAAO,EAAE,kCAAkC,UAE7B,OAAO,OAAO,QAAQ,UAqCrC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createImportMap } from '@ms-cloudpack/import-map';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { getBoostrapInlineScript, getInlineScripts } from './inlineScripts/getInlineScripts.js';
|
|
4
|
+
import { getCookies } from './getCookies.js';
|
|
5
|
+
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
6
|
+
const getBootstrapScript = async (input) => {
|
|
7
|
+
let bootstrapInlineScript = await getBoostrapInlineScript();
|
|
8
|
+
// Remove the export statement from the inline script, the bootstrap can not be an esm.
|
|
9
|
+
bootstrapInlineScript = bootstrapInlineScript.replace('export {};', '');
|
|
10
|
+
// Inject the boostrap inline script
|
|
11
|
+
// Call the bootstrap function with the input
|
|
12
|
+
return `
|
|
13
|
+
${bootstrapInlineScript}
|
|
14
|
+
window.__cloudpack.bootstrap(${JSON.stringify(input)});
|
|
15
|
+
`;
|
|
16
|
+
};
|
|
17
|
+
export function createBootstrapRouteHandler(options, context) {
|
|
18
|
+
return (_req, res) => {
|
|
19
|
+
(async () => {
|
|
20
|
+
const { definitionName, exportEntry } = options;
|
|
21
|
+
const { session } = context;
|
|
22
|
+
const { bundleServer: bundleServerUrl, apiServer: apiServerUrl } = session.urls;
|
|
23
|
+
if (!bundleServerUrl) {
|
|
24
|
+
// Sanity check...
|
|
25
|
+
throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');
|
|
26
|
+
}
|
|
27
|
+
const importMap = (session.importMap ??= await createImportMap({
|
|
28
|
+
...context,
|
|
29
|
+
...session,
|
|
30
|
+
urls: { bundleServer: bundleServerUrl },
|
|
31
|
+
}));
|
|
32
|
+
const inlineScripts = await getInlineScripts();
|
|
33
|
+
const cookies = getCookies(session, apiServerUrl, bundleServerUrl);
|
|
34
|
+
const entryScript = exportEntry && importMap.imports[slash(join(definitionName, exportEntry))];
|
|
35
|
+
const overlayScript = importMap.imports['@ms-cloudpack/overlay'];
|
|
36
|
+
const renderedContent = await getBootstrapScript({
|
|
37
|
+
importMap,
|
|
38
|
+
cookies,
|
|
39
|
+
overlayScript,
|
|
40
|
+
inlineScripts,
|
|
41
|
+
entryScript,
|
|
42
|
+
});
|
|
43
|
+
return res.type('application/javascript').send(renderedContent).end();
|
|
44
|
+
})().catch((err) => {
|
|
45
|
+
console.error(err?.stack || err);
|
|
46
|
+
return res.status(500).send(`Error loading app: ${err}`);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=createBootstrapRouteHandler.js.map
|
|
@@ -0,0 +1 @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D,GAAG,OAAO;gBACV,GAAG,OAAO;gBACV,IAAI,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE;aACxC,CAAC,CAAC,CAAC;YAEJ,MAAM,aAAa,GAAG,MAAM,gBAAgB,EAAE,CAAC;YAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC;YACnE,MAAM,WAAW,GAAG,WAAW,IAAI,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;YAC/F,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;YAEjE,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC;gBAC/C,SAAS;gBACT,OAAO;gBACP,aAAa;gBACb,aAAa;gBACb,WAAW;aACZ,CAAC,CAAC;YAEH,OAAO,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,GAAG,EAAE,CAAC;QACxE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACjB,OAAO,CAAC,KAAK,CAAE,GAAa,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;YAC5C,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Context } from '@ms-cloudpack/api-server';\nimport { createImportMap, type ImportMap } from '@ms-cloudpack/import-map';\nimport { join } from 'path';\nimport { getBoostrapInlineScript, getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { getCookies } from './getCookies.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport type { Request, Response } from '@ms-cloudpack/create-express-app';\n\nconst getBootstrapScript = async (input: {\n inlineScripts: string[];\n overlayScript: string;\n importMap: ImportMap;\n cookies: Record<string, string>;\n entryScript?: string;\n}) => {\n let bootstrapInlineScript = await getBoostrapInlineScript();\n\n // Remove the export statement from the inline script, the bootstrap can not be an esm.\n bootstrapInlineScript = bootstrapInlineScript.replace('export {};', '');\n\n // Inject the boostrap inline script\n // Call the bootstrap function with the input\n return `\n ${bootstrapInlineScript}\n window.__cloudpack.bootstrap(${JSON.stringify(input)});\n `;\n};\n\ntype CreateBootstrapRouteHandlerContext = Pick<\n Context,\n 'packages' | 'packageImportPaths' | 'packageHashes' | 'session'\n>;\n\nexport function createBootstrapRouteHandler(\n options: {\n definitionName: string;\n exportEntry?: string;\n },\n context: CreateBootstrapRouteHandlerContext,\n) {\n return (_req: Request, res: Response) => {\n (async () => {\n const { definitionName, exportEntry } = options;\n\n const { session } = context;\n const { bundleServer: bundleServerUrl, apiServer: apiServerUrl } = session.urls;\n\n if (!bundleServerUrl) {\n // Sanity check...\n throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');\n }\n\n const importMap = (session.importMap ??= await createImportMap({\n ...context,\n ...session,\n urls: { bundleServer: bundleServerUrl },\n }));\n\n const inlineScripts = await getInlineScripts();\n const cookies = getCookies(session, apiServerUrl, bundleServerUrl);\n const entryScript = exportEntry && importMap.imports[slash(join(definitionName, exportEntry))];\n const overlayScript = importMap.imports['@ms-cloudpack/overlay'];\n\n const renderedContent = await getBootstrapScript({\n importMap,\n cookies,\n overlayScript,\n inlineScripts,\n entryScript,\n });\n\n return res.type('application/javascript').send(renderedContent).end();\n })().catch((err) => {\n console.error((err as Error)?.stack || err);\n return res.status(500).send(`Error loading app: ${err}`);\n });\n };\n}\n"]}
|
package/lib/createRoutes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from '@ms-cloudpack/api-server';
|
|
2
|
-
import type
|
|
2
|
+
import { type PackageJson } from '@ms-cloudpack/common-types';
|
|
3
3
|
import type { Express } from '@ms-cloudpack/create-express-app';
|
|
4
4
|
interface CreateRoutesOptions {
|
|
5
5
|
app: Express;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAIL,KAAK,WAAW,EAEjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,kCAAkC,CAAC;AAUnF,UAAU,mBAAmB;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,WAAW,CAAC;CACzB;AAED,KAAK,mBAAmB,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,oBAAoB,GAAG,eAAe,GAAG,SAAS,CAAC,CAAC;AAE1G;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,QA8CtF"}
|
package/lib/createRoutes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isBootstrapRoute, isRenderedRoute, isStaticRoute, } from '@ms-cloudpack/common-types';
|
|
1
2
|
import { express } from '@ms-cloudpack/create-express-app';
|
|
2
3
|
import { createImportMap } from '@ms-cloudpack/import-map';
|
|
3
4
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
@@ -5,6 +6,7 @@ import path from 'path';
|
|
|
5
6
|
import { getInlineScripts } from './inlineScripts/getInlineScripts.js';
|
|
6
7
|
import { renderRoute } from './renderRoute/renderRoute.js';
|
|
7
8
|
import { setHeaders } from './setHeaders.js';
|
|
9
|
+
import { createBootstrapRouteHandler } from './createBootstrapRouteHandler.js';
|
|
8
10
|
/**
|
|
9
11
|
* Creates the routes for the express app based on the config.
|
|
10
12
|
*/
|
|
@@ -12,6 +14,9 @@ export function createRoutes(options, context) {
|
|
|
12
14
|
const { app, ...otherOptions } = options;
|
|
13
15
|
const { session } = context;
|
|
14
16
|
const routes = [...(session.config.devServer?.routes || [])];
|
|
17
|
+
if (!options.definition.name) {
|
|
18
|
+
throw new Error('Name field is required in the package.json file.');
|
|
19
|
+
}
|
|
15
20
|
// Only as a basic fallback if no routes are specified, add a default catch-all route.
|
|
16
21
|
// Adding this automatically has the risk of hiding errors, like if an unexpected path
|
|
17
22
|
// being requested, or a JS file somehow being loaded from the app server unexpectedly.
|
|
@@ -24,10 +29,16 @@ export function createRoutes(options, context) {
|
|
|
24
29
|
routes.push(fallbackRoute);
|
|
25
30
|
}
|
|
26
31
|
for (const route of routes) {
|
|
27
|
-
if (route
|
|
32
|
+
if (isStaticRoute(route)) {
|
|
28
33
|
app.use(route.match, express.static(path.resolve(session.appPath, route.staticPath)));
|
|
29
34
|
}
|
|
30
|
-
else {
|
|
35
|
+
else if (isBootstrapRoute(route)) {
|
|
36
|
+
app.get(route.match, createBootstrapRouteHandler({
|
|
37
|
+
exportEntry: route.exportEntry,
|
|
38
|
+
definitionName: options.definition.name,
|
|
39
|
+
}, context));
|
|
40
|
+
}
|
|
41
|
+
else if (isRenderedRoute(route)) {
|
|
31
42
|
app.get(route.match, (req, res) => {
|
|
32
43
|
handleRequest({ ...otherOptions, route, req, res }, context).catch((err) => {
|
|
33
44
|
console.error(err?.stack || err);
|
|
@@ -35,6 +46,9 @@ export function createRoutes(options, context) {
|
|
|
35
46
|
});
|
|
36
47
|
});
|
|
37
48
|
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error(`Unknown route: ${JSON.stringify(route)}`);
|
|
51
|
+
}
|
|
38
52
|
}
|
|
39
53
|
}
|
|
40
54
|
async function handleRequest(options, context) {
|
|
@@ -52,9 +66,8 @@ async function handleRequest(options, context) {
|
|
|
52
66
|
const requestPath = slash(req.path.substring(1));
|
|
53
67
|
const requestExt = path.extname(requestPath);
|
|
54
68
|
const overlayScript = importMap.imports['@ms-cloudpack/overlay'];
|
|
55
|
-
const entryScript =
|
|
56
69
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
|
-
route.exportEntry && importMap.imports[slash(path.join(definition.name, route.exportEntry))];
|
|
70
|
+
const entryScript = route.exportEntry && importMap.imports[slash(path.join(definition.name, route.exportEntry))];
|
|
58
71
|
// Set the appropriate Cloudpack headers/cookies in the response.
|
|
59
72
|
// TODO: setting the headers here prohibits cases where the page rendering is owned by existing server code
|
|
60
73
|
// that can only accept changing the scripts. We should consider moving to a model where an initial script
|
package/lib/createRoutes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,aAAa,GAGd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAsB,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAU/E;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B,EAAE,OAA4B;IACrF,MAAM,EAAE,GAAG,E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UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACjE,oEAAoE;IACpE,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAK,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAElH,iEAAiE;IACjE,2GAA2G;IAC3G,0GAA0G;IAC1G,uGAAuG;IACvG,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;IAE7B,MAAM,aAAa,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAC/C,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,WAAW,CAAC;QAC7D,GAAG,OAAO;QACV,OAAO;QACP,OAAO,EAAE,GAAG;QACZ,SAAS;QACT,aAAa;QACb,WAAW;QACX,aAAa;KACd,CAAC,CAAC;IAEH,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;IAE7D,OAAO,CAAC,KAAK,CAAC,wBAAwB,WAAW,UAAU,UAAU,EAAE,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import type { Context } from '@ms-cloudpack/api-server';\nimport {\n isBootstrapRoute,\n isRenderedRoute,\n isStaticRoute,\n type PackageJson,\n type RenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport type { Express, Request, Response } from '@ms-cloudpack/create-express-app';\nimport { express } from '@ms-cloudpack/create-express-app';\nimport { createImportMap } from '@ms-cloudpack/import-map';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport { getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { renderRoute, type RouteInternal } from './renderRoute/renderRoute.js';\nimport { setHeaders } from './setHeaders.js';\nimport { createBootstrapRouteHandler } from './createBootstrapRouteHandler.js';\n\ninterface CreateRoutesOptions {\n app: Express;\n url: string;\n definition: PackageJson;\n}\n\ntype CreateRoutesContext = Pick<Context, 'packages' | 'packageImportPaths' | 'packageHashes' | 'session'>;\n\n/**\n * Creates the routes for the express app based on the config.\n */\nexport function createRoutes(options: CreateRoutesOptions, context: CreateRoutesContext) {\n const { app, ...otherOptions } = options;\n const { session } = context;\n const routes = [...(session.config.devServer?.routes || [])];\n\n if (!options.definition.name) {\n throw new Error('Name field is required in the package.json file.');\n }\n\n // Only as a basic fallback if no routes are specified, add a default catch-all route.\n // Adding this automatically has the risk of hiding errors, like if an unexpected path\n // being requested, or a JS file somehow being loaded from the app server unexpectedly.\n if (!routes.length) {\n const fallbackRoute: RouteInternal = {\n match: '*',\n exportEntry: '.',\n isDefaultFallback: true, // this internal property is read by renderRoute\n };\n routes.push(fallbackRoute);\n }\n\n for (const route of routes) {\n if (isStaticRoute(route)) {\n app.use(route.match, express.static(path.resolve(session.appPath, route.staticPath)));\n } else if (isBootstrapRoute(route)) {\n app.get(\n route.match,\n createBootstrapRouteHandler(\n {\n exportEntry: route.exportEntry,\n definitionName: options.definition.name,\n },\n context,\n ),\n );\n } else if (isRenderedRoute(route)) {\n app.get(route.match, (req, res) => {\n handleRequest({ ...otherOptions, route, req, res }, context).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error loading app: ${err}`);\n });\n });\n } else {\n throw new Error(`Unknown route: ${JSON.stringify(route)}`);\n }\n }\n}\n\nasync function handleRequest(\n options: Omit<CreateRoutesOptions, 'app'> & {\n req: Request;\n res: Response;\n route: RenderedRoute;\n },\n context: CreateRoutesContext,\n) {\n const { req, res, definition, route, url } = options;\n const { session } = context;\n const { bundleServer } = session.urls;\n if (!bundleServer) {\n // Sanity check...\n throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');\n }\n\n // Build the import map if it hasn't been built yet for this session version.\n // (TS can't infer that urls.bundleServer is set on session from a check above.)\n const importMap = (session.importMap ??= await createImportMap({ ...context, ...session, urls: { bundleServer } }));\n\n // Parse the request path, extension, grab the overlay script path.\n const requestPath = slash(req.path.substring(1));\n const requestExt = path.extname(requestPath);\n const overlayScript = importMap.imports['@ms-cloudpack/overlay'];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const entryScript = route.exportEntry && importMap.imports[slash(path.join(definition.name!, route.exportEntry))];\n\n // Set the appropriate Cloudpack headers/cookies in the response.\n // TODO: setting the headers here prohibits cases where the page rendering is owned by existing server code\n // that can only accept changing the scripts. We should consider moving to a model where an initial script\n // fetch loads the import map and sets Cloudpack settings in local storage rather than headers/cookies.\n setHeaders({ res, session });\n\n const inlineScripts = await getInlineScripts();\n const { content, statusCode, contentType } = await renderRoute({\n ...options,\n session,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n inlineScripts,\n });\n\n res.type(contentType).status(statusCode).send(content).end();\n\n console.debug(`App server: Request: ${requestPath}, ext: ${requestExt}`);\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Session } from '@ms-cloudpack/api-server';
|
|
2
|
+
/**
|
|
3
|
+
* Get the cookies that needs to be written on the page for Cloudpack to work properly.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getCookies(session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'sessionVersion'>, apiServerUrl?: string, bundleServerUrl?: string): Record<string, string>;
|
|
6
|
+
//# sourceMappingURL=getCookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCookies.d.ts","sourceRoot":"","sources":["../src/getCookies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGxD;;GAEG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,gBAAgB,CAAC,EAC5E,YAAY,CAAC,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { cookieNames, getCloudpackSessionVersionCookie } from './cookieNames.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the cookies that needs to be written on the page for Cloudpack to work properly.
|
|
4
|
+
*/
|
|
5
|
+
export function getCookies(session, apiServerUrl, bundleServerUrl) {
|
|
6
|
+
return {
|
|
7
|
+
[cookieNames.sessionId]: session.id,
|
|
8
|
+
[cookieNames.sessionSequence]: session.sequence.toString(),
|
|
9
|
+
[getCloudpackSessionVersionCookie(session.projectName)]: session.sessionVersion.toString(),
|
|
10
|
+
[cookieNames.apiUrl]: apiServerUrl ?? '',
|
|
11
|
+
[cookieNames.bundleServerUrl]: bundleServerUrl ?? '',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=getCookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCookies.js","sourceRoot":"","sources":["../src/getCookies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEjF;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,OAA4E,EAC5E,YAAqB,EACrB,eAAwB;IAExB,OAAO;QACL,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,EAAE;QACnC,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE;QAC1D,CAAC,gCAAgC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE;QAC1F,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,YAAY,IAAI,EAAE;QACxC,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,eAAe,IAAI,EAAE;KACrD,CAAC;AACJ,CAAC","sourcesContent":["import type { Session } from '@ms-cloudpack/api-server';\nimport { cookieNames, getCloudpackSessionVersionCookie } from './cookieNames.js';\n\n/**\n * Get the cookies that needs to be written on the page for Cloudpack to work properly.\n */\nexport function getCookies(\n session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'sessionVersion'>,\n apiServerUrl?: string,\n bundleServerUrl?: string,\n): Record<string, string> {\n return {\n [cookieNames.sessionId]: session.id,\n [cookieNames.sessionSequence]: session.sequence.toString(),\n [getCloudpackSessionVersionCookie(session.projectName)]: session.sessionVersion.toString(),\n [cookieNames.apiUrl]: apiServerUrl ?? '',\n [cookieNames.bundleServerUrl]: bundleServerUrl ?? '',\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.inline.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/bootstrap.inline.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
window.__cloudpack ??= {};
|
|
2
|
+
window.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, cookies, entryScript }) => {
|
|
3
|
+
// Inject the import map
|
|
4
|
+
const importMapScriptTag = document.createElement('script');
|
|
5
|
+
importMapScriptTag.type = 'importmap';
|
|
6
|
+
importMapScriptTag.textContent = JSON.stringify(importMap);
|
|
7
|
+
document.head.appendChild(importMapScriptTag);
|
|
8
|
+
// Inject cookies into localStorage
|
|
9
|
+
Object.entries(cookies).forEach(([key, value]) => {
|
|
10
|
+
localStorage.setItem(key, value);
|
|
11
|
+
});
|
|
12
|
+
// Inject the inline scripts
|
|
13
|
+
for (const inlineScript of inlineScripts) {
|
|
14
|
+
const inlineTag = document.createElement('script');
|
|
15
|
+
inlineTag.type = 'module';
|
|
16
|
+
inlineTag.textContent = inlineScript;
|
|
17
|
+
document.head.appendChild(inlineTag);
|
|
18
|
+
}
|
|
19
|
+
// Inject the overlay script
|
|
20
|
+
const overlayScriptTag = document.createElement('script');
|
|
21
|
+
overlayScriptTag.type = 'module';
|
|
22
|
+
overlayScriptTag.src = overlayScript;
|
|
23
|
+
document.head.appendChild(overlayScriptTag);
|
|
24
|
+
// Inject the main script
|
|
25
|
+
if (entryScript) {
|
|
26
|
+
const entryScriptTag = document.createElement('script');
|
|
27
|
+
entryScriptTag.type = 'module';
|
|
28
|
+
entryScriptTag.src = entryScript;
|
|
29
|
+
document.head.appendChild(entryScriptTag);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=bootstrap.inline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/bootstrap.inline.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;AAC1B,MAAM,CAAC,WAAW,CAAC,SAAS,GAAG,CAAC,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE;IACnG,wBAAwB;IACxB,MAAM,kBAAkB,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC5D,kBAAkB,CAAC,IAAI,GAAG,WAAW,CAAC;IACtC,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC3D,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IAE9C,mCAAmC;IACnC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC/C,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,4BAA4B;IAC5B,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACnD,SAAS,CAAC,IAAI,GAAG,QAAQ,CAAC;QAC1B,SAAS,CAAC,WAAW,GAAG,YAAY,CAAC;QACrC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,4BAA4B;IAC5B,MAAM,gBAAgB,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC1D,gBAAgB,CAAC,IAAI,GAAG,QAAQ,CAAC;IACjC,gBAAgB,CAAC,GAAG,GAAG,aAAa,CAAC;IACrC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAE5C,yBAAyB;IACzB,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxD,cAAc,CAAC,IAAI,GAAG,QAAQ,CAAC;QAC/B,cAAc,CAAC,GAAG,GAAG,WAAW,CAAC;QACjC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC,CAAC","sourcesContent":["window.__cloudpack ??= {};\nwindow.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, cookies, entryScript }) => {\n // Inject the import map\n const importMapScriptTag = document.createElement('script');\n importMapScriptTag.type = 'importmap';\n importMapScriptTag.textContent = JSON.stringify(importMap);\n document.head.appendChild(importMapScriptTag);\n\n // Inject cookies into localStorage\n Object.entries(cookies).forEach(([key, value]) => {\n localStorage.setItem(key, value);\n });\n\n // Inject the inline scripts\n for (const inlineScript of inlineScripts) {\n const inlineTag = document.createElement('script');\n inlineTag.type = 'module';\n inlineTag.textContent = inlineScript;\n document.head.appendChild(inlineTag);\n }\n\n // Inject the overlay script\n const overlayScriptTag = document.createElement('script');\n overlayScriptTag.type = 'module';\n overlayScriptTag.src = overlayScript;\n document.head.appendChild(overlayScriptTag);\n\n // Inject the main script\n if (entryScript) {\n const entryScriptTag = document.createElement('script');\n entryScriptTag.type = 'module';\n entryScriptTag.src = entryScript;\n document.head.appendChild(entryScriptTag);\n }\n};\n"]}
|
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
// Typing hack to ensure this name is correct while working around the limitation on runtime imports
|
|
3
3
|
const cloudpackBundleServerUrlCookie = 'cloudpack-bundle-server-url';
|
|
4
4
|
const scriptLoadResults = {};
|
|
5
|
-
function
|
|
5
|
+
function getCookieOrLocalStorage(cname) {
|
|
6
6
|
const decodedCookies = decodeURIComponent(document.cookie);
|
|
7
7
|
const cookies = decodedCookies.split(';');
|
|
8
8
|
const keyValues = cookies.map((cookie) => cookie.split('='));
|
|
9
9
|
const cookie = keyValues.find(([key]) => key.trim() === cname);
|
|
10
10
|
if (!cookie) {
|
|
11
|
+
const result = localStorage.getItem(cname);
|
|
12
|
+
if (result) {
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
11
15
|
throw new Error(`Cookie ${cname} not found`);
|
|
12
16
|
}
|
|
13
17
|
return cookie[1].trim();
|
|
14
18
|
}
|
|
15
|
-
const bundleServerUrl =
|
|
19
|
+
const bundleServerUrl = getCookieOrLocalStorage(cloudpackBundleServerUrlCookie);
|
|
16
20
|
function isPerformanceResourceTiming(entry) {
|
|
17
21
|
return entry.entryType === 'resource';
|
|
18
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBrowserCacheRatio.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/getBrowserCacheRatio.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAInG,oGAAoG;AACpG,MAAM,8BAA8B,GAA4C,6BAA6B,CAAC;AAE9G,MAAM,iBAAiB,GAAwC,EAAE,CAAC;AAElE,SAAS,
|
|
1
|
+
{"version":3,"file":"getBrowserCacheRatio.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/getBrowserCacheRatio.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I,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;AACH,CAAC;AAED,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;IACpD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;QACrC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,4DAA4D;AAC5D,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;IAC7D,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,0DAA0D;AAC1D,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAE3D,SAAS,oBAAoB;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,MAAM,CAAC;IACjG,MAAM,KAAK,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC;IAEjE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;AAC1B,MAAM,CAAC,WAAW,CAAC,oBAAoB,GAAG,oBAAoB,CAAC","sourcesContent":["// This file must NOT import other files (except types), because they won't be resolved at runtime.\n\nimport type { cookieNames } from '../cookieNames.js';\n\n// Typing hack to ensure this name is correct while working around the limitation on runtime imports\nconst cloudpackBundleServerUrlCookie: (typeof cookieNames)['bundleServerUrl'] = 'cloudpack-bundle-server-url';\n\nconst scriptLoadResults: Record<string, 'cache' | 'network'> = {};\n\nfunction getCookieOrLocalStorage(cname: string) {\n const decodedCookies = decodeURIComponent(document.cookie);\n const cookies = decodedCookies.split(';');\n const keyValues = cookies.map((cookie) => cookie.split('='));\n const cookie = keyValues.find(([key]) => key.trim() === cname);\n if (!cookie) {\n const result = localStorage.getItem(cname);\n if (result) {\n return result;\n }\n throw new Error(`Cookie ${cname} not found`);\n }\n\n return cookie[1].trim();\n}\n\nconst bundleServerUrl = getCookieOrLocalStorage(cloudpackBundleServerUrlCookie);\n\nfunction isPerformanceResourceTiming(entry: PerformanceEntry): entry is PerformanceResourceTiming {\n return entry.entryType === 'resource';\n}\n\nfunction handlePerformanceEntry(item: PerformanceEntry) {\n if (isPerformanceResourceTiming(item) && item.name.startsWith(bundleServerUrl)) {\n scriptLoadResults[item.name] = item.transferSize === 0 ? 'cache' : 'network';\n }\n}\n\nconst perfObserver = new PerformanceObserver((list) => {\n for (const item of list.getEntries()) {\n handlePerformanceEntry(item);\n }\n});\n\n// Get all the resources that were loaded before this script\nfor (const entry of performance.getEntriesByType('resource')) {\n handlePerformanceEntry(entry);\n}\n\n// Observe all resources that are loaded after this script\nperfObserver.observe({ type: 'resource', buffered: true });\n\nfunction getBrowserCacheRatio() {\n const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;\n const ratio = cacheCount / Object.keys(scriptLoadResults).length;\n\n return ratio;\n}\n\nwindow.__cloudpack ??= {};\nwindow.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;\n"]}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads all the inline scripts except bootstrap from the file system and returns them. It caches the result for subsequent calls.
|
|
3
|
+
* @returns The inline scripts excluding bootstrap.
|
|
4
|
+
*/
|
|
1
5
|
export declare function getInlineScripts(): Promise<string[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Reads the bootstrap inline script from the file system and returns it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getBoostrapInlineScript(): Promise<string>;
|
|
2
10
|
//# sourceMappingURL=getInlineScripts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInlineScripts.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getInlineScripts.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAsB,gBAAgB,sBASrC;AAID;;GAEG;AACH,wBAAsB,uBAAuB,oBAQ5C"}
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import { globSourceFiles } from '@ms-cloudpack/path-utilities';
|
|
2
2
|
import fsPromises from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
async function readInlineScript(fileName) {
|
|
6
|
+
let content = await fsPromises.readFile(fileName, 'utf-8');
|
|
7
|
+
// Remove source maps from inline scripts to avoid warnings in the browser.
|
|
8
|
+
content = content.replace('# sourceMappingURL=', ' ');
|
|
9
|
+
return content;
|
|
10
|
+
}
|
|
3
11
|
let inlineScripts;
|
|
12
|
+
/**
|
|
13
|
+
* Reads all the inline scripts except bootstrap from the file system and returns them. It caches the result for subsequent calls.
|
|
14
|
+
* @returns The inline scripts excluding bootstrap.
|
|
15
|
+
*/
|
|
4
16
|
export async function getInlineScripts() {
|
|
5
17
|
if (!inlineScripts) {
|
|
6
|
-
const inlineScriptFiles = await globSourceFiles(import.meta.url, '*.inline');
|
|
7
|
-
inlineScripts = await Promise.all(inlineScriptFiles.map((filename) =>
|
|
8
|
-
// Remove source maps from inline scripts to avoid warnings in the browser.
|
|
9
|
-
inlineScripts = inlineScripts.map((script) => script.replace('# sourceMappingURL=', ' '));
|
|
18
|
+
const inlineScriptFiles = (await globSourceFiles(import.meta.url, '*.inline')).filter((file) => !file.includes('bootstrap.inline'));
|
|
19
|
+
inlineScripts = await Promise.all(inlineScriptFiles.map((filename) => readInlineScript(filename)));
|
|
10
20
|
}
|
|
11
21
|
return inlineScripts;
|
|
12
22
|
}
|
|
23
|
+
let bootstrapInlineScript;
|
|
24
|
+
/**
|
|
25
|
+
* Reads the bootstrap inline script from the file system and returns it.
|
|
26
|
+
*/
|
|
27
|
+
export async function getBoostrapInlineScript() {
|
|
28
|
+
if (!bootstrapInlineScript) {
|
|
29
|
+
bootstrapInlineScript = await readInlineScript(path.join(path.dirname(fileURLToPath(import.meta.url)), 'bootstrap.inline.js'));
|
|
30
|
+
}
|
|
31
|
+
return bootstrapInlineScript;
|
|
32
|
+
}
|
|
13
33
|
//# sourceMappingURL=getInlineScripts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInlineScripts.js","sourceRoot":"","sources":["../../src/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"getInlineScripts.js","sourceRoot":"","sources":["../../src/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IAC9C,IAAI,OAAO,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE3D,2EAA2E;IAC3E,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;IAEtD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,IAAI,aAAmC,CAAC;AAExC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,iBAAiB,GAAG,CAAC,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CACnF,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAC7C,CAAC;QACF,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrG,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,IAAI,qBAAyC,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,qBAAqB,GAAG,MAAM,gBAAgB,CAC5C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAC/E,CAAC;IACJ,CAAC;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC","sourcesContent":["import { globSourceFiles } from '@ms-cloudpack/path-utilities';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nasync function readInlineScript(fileName: string) {\n let content = await fsPromises.readFile(fileName, 'utf-8');\n\n // Remove source maps from inline scripts to avoid warnings in the browser.\n content = content.replace('# sourceMappingURL=', ' ');\n\n return content;\n}\n\nlet inlineScripts: string[] | undefined;\n\n/**\n * Reads all the inline scripts except bootstrap from the file system and returns them. It caches the result for subsequent calls.\n * @returns The inline scripts excluding bootstrap.\n */\nexport async function getInlineScripts() {\n if (!inlineScripts) {\n const inlineScriptFiles = (await globSourceFiles(import.meta.url, '*.inline')).filter(\n (file) => !file.includes('bootstrap.inline'),\n );\n inlineScripts = await Promise.all(inlineScriptFiles.map((filename) => readInlineScript(filename)));\n }\n\n return inlineScripts;\n}\n\nlet bootstrapInlineScript: string | undefined;\n\n/**\n * Reads the bootstrap inline script from the file system and returns it.\n */\nexport async function getBoostrapInlineScript() {\n if (!bootstrapInlineScript) {\n bootstrapInlineScript = await readInlineScript(\n path.join(path.dirname(fileURLToPath(import.meta.url)), 'bootstrap.inline.js'),\n );\n }\n\n return bootstrapInlineScript;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPageLoadTime.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/getPageLoadTime.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAInG,kGAAkG;AAClG,MAAM,gBAAgB,GAAgC,wBAAwB,CAAC;AAE/E;;;GAGG;AACH,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,8DAA8D;AAC9D,MAAM,WAAW,GAAa,CAAC,gBAAgB,CAAC,CAAC;AAIjD,SAAS,QAAQ,CAAsB,IAAqB,EAAE,IAAY;IACxE,IAAI,OAA6C,CAAC;IAElD,OAAO,UAAU,GAAG,IAAO;QACzB,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAChB,CAAC,CAAC;QAEF,IAAI,OAAO,EAAE,CAAC;YACZ,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,QAAwB;IAC3D,OAAO,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,MAAM,EAAE,GAAI,IAAwB,CAAC,EAAE,CAAC;QAExC,IAAI,EAAE,EAAE,CAAC;YACP,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;Q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,CAAC;IAE/F,SAAS,UAAU,CAAC,SAA2B;QAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAE/E,IAAI,aAAa,EAAE,CAAC;YAClB,qBAAqB,CAAC,GAAG,EAAE;gBACzB,kFAAkF;gBAClF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBAE/B,uBAAuB;gBACvB,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;gBAEvC,0BAA0B;gBAC1B,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAEjC,4BAA4B;gBAC5B,gCAAgC,CAAC,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE;QAC9B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;AAC1B,MAAM,CAAC,WAAW,CAAC,eAAe,GAAG,GAAG,EAAE,CAAC,mBAAmB,CAAC","sourcesContent":["// This file must NOT import other files (except types), because they won't be resolved at runtime.\n\nimport type { elementIds } from '@ms-cloudpack/overlay/constants';\n\n// Typing hack to ensure this ID is correct while working around the limitation on runtime imports\nconst overlayRootDivId: (typeof elementIds)['root'] = 'cloudpack-overlay-root';\n\n/**\n * Performance mark name for page load time.\n * This makes it easier to see the page load time in the performance tab in dev tools\n */\nconst pageLoadMarker = 'CLOUDPACK_PAGE_LOAD_TIME';\n\n// The below dom elements will be ignored by mutation observer\nconst excludedIds: string[] = [overlayRootDivId];\n\ntype DebounceFunc<T extends unknown[]> = (...args: T) => void;\n\nfunction debounce<T extends unknown[]>(func: DebounceFunc<T>, wait: number): DebounceFunc<T> {\n let timeout: ReturnType<typeof setTimeout> | null;\n\n return function (...args: T) {\n const later = () => {\n timeout = null;\n func(...args);\n };\n\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(later, wait);\n };\n}\n\nfunction hasMutationNonExcludedNodes(mutation: MutationRecord) {\n return [...mutation.addedNodes].some((node) => {\n const id = (node as { id?: string }).id;\n\n if (id) {\n return !excludedIds.includes(id);\n }\n\n return true;\n });\n}\n\nconst pageLoadTimePromise = new Promise<number>((resolve) => {\n const observer = new MutationObserver(domChanged);\n\n function reportLastAnimationTime(time: number) {\n // Stop observing the DOM\n observer.disconnect();\n\n // Resolve the promise with the page load time\n resolve(time);\n }\n\n const debouncedReportLastAnimationTime = debounce(reportLastAnimationTime, 2000 /* wait ms */);\n\n function domChanged(mutations: MutationRecord[]) {\n const shouldProcess = mutations.filter(hasMutationNonExcludedNodes).length > 0;\n\n if (shouldProcess) {\n requestAnimationFrame(() => {\n // Get the current time in ms since the time when navigation has started in window\n const time = performance.now();\n\n // Clear previous marks\n performance.clearMarks(pageLoadMarker);\n\n // Mark the page load time\n performance.mark(pageLoadMarker);\n\n // Report the page load time\n debouncedReportLastAnimationTime(time);\n });\n }\n }\n\n observer.observe(document.body, {\n childList: true,\n });\n});\n\nwindow.__cloudpack ??= {};\nwindow.__cloudpack.getPageLoadTime = () => pageLoadTimePromise;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RenderedRoute } from '@ms-cloudpack/common-types';
|
|
2
2
|
import type { RenderRouteOptions } from '../types/RenderRouteOptions.js';
|
|
3
3
|
import type { CompleteRenderRouteResult } from '../types/RenderRouteResult.js';
|
|
4
|
-
export type RouteInternal =
|
|
4
|
+
export type RouteInternal = RenderedRoute & {
|
|
5
5
|
isDefaultFallback?: boolean;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRoute.d.ts","sourceRoot":"","sources":["../../src/renderRoute/renderRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"renderRoute.d.ts","sourceRoot":"","sources":["../../src/renderRoute/renderRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAOhE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAqB,MAAM,+BAA+B,CAAC;AAKlG,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAoDjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRoute.js","sourceRoot":"","sources":["../../src/renderRoute/renderRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAKpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAIjE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAA2B;IAC3D,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAExC,iGAAiG;IACjG,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;IAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7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@ms-cloudpack/common-types';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport fsPromises from 'fs/promises';\nimport { JSDOM } from 'jsdom';\nimport path from 'path';\nimport { pathToFileURL } from 'url';\nimport type { RenderRouteFunction } from '../types/RenderRouteFunction.js';\nimport type { RenderRouteOptions } from '../types/RenderRouteOptions.js';\nimport type { CompleteRenderRouteResult, RenderRouteResult } from '../types/RenderRouteResult.js';\nimport type { RenderRouteScript } from '../types/RenderRouteScript.js';\nimport { getDefaultHtmlResponse } from './getDefaultHtmlResponse.js';\nimport { getHtmlErrorResponse } from './getHtmlErrorResponse.js';\n\nexport type RouteInternal = Route & { isDefaultFallback?: boolean };\n\n/**\n * Get the response for the given route. If the route has a custom render script, use that.\n * Returns an error response if the file referenced by the script doesn't exist or throws an error.\n */\nexport async function renderRoute(options: RenderRouteOptions): Promise<CompleteRenderRouteResult> {\n const { route, session, req } = options;\n\n // Get the request path and extension (the URL.pathname conversion gets rid of any query or hash)\n const requestPath = makeUrl(req.url, options.baseUrl).pathname;\n const requestExt = path.extname(requestPath);\n // Determine whether HTML is (probably) an acceptable response type (can be refined later if needed).\n // In theory we should be able to use req.accepts() but not all requests set the accept header.\n const isHtmlAcceptable =\n (!requestExt || requestExt.startsWith('.htm')) && !req.xhr && isHtmlType(req.headers.accept || '*/*');\n\n // Get an initial result from either the render script or default handler.\n let rawResult: RenderRouteResult;\n const renderScriptPath = route.renderScript && path.resolve(session.appPath, route.renderScript);\n if (renderScriptPath) {\n const scriptExt = path.extname(renderScriptPath).toLowerCase();\n if (scriptExt === '.html' || scriptExt === '.htm') {\n rawResult = await readStaticHtml(renderScriptPath);\n } else {\n rawResult = await renderCustomScript({ ...options, renderScriptPath });\n }\n } else {\n rawResult = await getDefaultHtmlResponse(options);\n }\n\n const result: CompleteRenderRouteResult = {\n contentType: 'text/html',\n statusCode: 200,\n ...(typeof rawResult === 'string' ? { content: rawResult } : rawResult),\n };\n\n // If it's HTML and a success statusCode, inject the import map and appropriate scripts.\n if (result.statusCode === 200 && isHtmlType(result.contentType)) {\n // First verify that we're not accidentally returning HTML if a different file type is requested.\n // This could happen for overly broad route matches such as '*', or if no routes are configured.\n if (!isHtmlAcceptable) {\n const renderer = route.renderScript ? `renderScript \"${renderScriptPath}\"` : 'the default renderer';\n const content = (route as RouteInternal).isDefaultFallback\n ? // no routes configured\n `Cloudpack's default route can only return HTML, but this appears to be a non-HTML request. ` +\n `Please add a route under devServer.routes in the cloudpack config.`\n : // route with or without custom renderer\n `Route \"${route.match}\" with ${renderer} returned HTML, but this appears to be a non-HTML request. ` +\n `This is likely a misconfiguration of devServer.routes in the cloudpack config.`;\n return { statusCode: 500, contentType: 'text/plain', content };\n }\n\n // Inject the import map and scripts.\n injectScripts(options, result);\n }\n\n return result;\n}\n\nfunction isHtmlType(acceptOrContentType: string) {\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n return acceptOrContentType\n .split(',')\n .map((s) => s.split(';')[0].trim())\n .some((mime) => mime === '*/*' || /xml|x?html/i.test(mime) || /^(text|application)\\/\\*$/.test(mime));\n}\n\n/**\n * Load the default export from a JS file passed as the `renderScript` in a route,\n * and return either the result of running the function, or an error page if something fails.\n */\nasync function renderCustomScript(\n params: RenderRouteOptions & { renderScriptPath: string },\n): Promise<RenderRouteResult> {\n const { renderScriptPath, ...options } = params;\n // Get the html factory function from a script default export.\n const renderScriptUrl = pathToFileURL(renderScriptPath).toString();\n\n // Note: because there isn't a way to purge the require cache, we need to add a cache breaker query param to the\n // script path to ensure we get the latest version of the script. This could be improved by using the git hash of\n // the file if it exists, or a hash of the content, or even the timestamp of the file.\n let cacheBreakerQueryParam = `?t=${Date.now()}`;\n try {\n const { mtime } = await fsPromises.stat(renderScriptPath);\n cacheBreakerQueryParam = `?t=${mtime.getTime()}`;\n } catch {\n /* no-op */\n }\n\n // Try importing the script\n let createHtml: RenderRouteFunction | undefined;\n let errorMessage: string | undefined;\n try {\n const importResult = ((await import(renderScriptUrl + cacheBreakerQueryParam)) as RenderRouteScript).default;\n if (typeof importResult === 'function') {\n createHtml = importResult;\n } else {\n errorMessage = `The render script at \"${renderScriptPath}\" does not export a default function.`;\n }\n } catch (e) {\n errorMessage = `Error importing render script at \"${renderScriptUrl}\":\\n${(e as Error).stack || e}`;\n }\n\n if (createHtml) {\n // Try running the script\n try {\n return await createHtml(options);\n } catch (e) {\n errorMessage = `Error running render script at \"${renderScriptPath}\":\\n${(e as Error).stack || e}`;\n }\n }\n\n // Return an error page. Doing this instead of returning a default or empty response ensures that\n // the user is aware of any configuration issues.\n errorMessage ??= `Unknown error loading render script at \"${renderScriptPath}\".`;\n console.error(errorMessage);\n return getHtmlErrorResponse(errorMessage);\n}\n\n/**\n * Modify the HTML response by injecting the import map, inline scripts, and entry/overlay scripts.\n *\n * Note that this just logs an error rather than returning an error response if something fails, for now.\n */\nfunction injectScripts(options: RenderRouteOptions, result: CompleteRenderRouteResult): void {\n const { route, overlayScript, entryScript, inlineScripts, importMap } = options;\n let jsdom: JSDOM;\n try {\n jsdom = new JSDOM(result.content, { contentType: result.contentType } as ConstructorParameters<typeof JSDOM>[1]);\n } catch (e) {\n // Trying to write a test for the above, it seemed very permissive, but catch just in case\n console.error(`Error parsing html response for rendering route \"${route.match}\":\\n${(e as Error).stack || e}`);\n return;\n }\n\n try {\n const { document } = jsdom.window;\n\n if (entryScript || overlayScript) {\n // Inject the import map at the top of the head, in case other scripts use it\n addScript({ document, type: 'importmap', prepend: true, content: JSON.stringify(importMap, null, 2) });\n }\n\n for (const inlineScript of inlineScripts) {\n addScript({ document, content: inlineScript });\n }\n\n // inject the overlay and entry scripts\n addScript({ document, url: overlayScript });\n addScript({ document, url: entryScript });\n\n result.content = jsdom.serialize();\n } catch (e) {\n console.error(`Error injecting scripts for route \"${route.match}\":\\n${(e as Error).stack || e}`);\n }\n}\n\n/**\n * Helper function to add a script to the document.\n */\nfunction addScript(params: { document: Document; type?: string; prepend?: boolean; url?: string; content?: string }) {\n const { document, type = 'module', prepend, url, content } = params;\n if (!url && !content) {\n return;\n }\n\n const script = document.createElement('script');\n script.type = type;\n if (url) {\n script.src = url;\n } else if (content) {\n script.innerHTML = content;\n }\n\n if (prepend) {\n document.head.prepend(script);\n } else {\n document.head.appendChild(script);\n }\n}\n\n/**\n * Read a static HTML file, or return an error response if the file can't be read.\n */\nasync function readStaticHtml(renderScriptPath: string): Promise<RenderRouteResult> {\n try {\n return (await fsPromises.readFile(renderScriptPath, 'utf8')) || '';\n } catch (e) {\n const message = `Error reading HTML file at \"${renderScriptPath}\":\\n${(e as Error).stack || e}`;\n console.error(message);\n return getHtmlErrorResponse(message);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"renderRoute.js","sourceRoot":"","sources":["../../src/renderRoute/renderRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAKpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAIjE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAA2B;IAC3D,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAExC,iGAAiG;IACjG,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAA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,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import type { RenderedRoute } from '@ms-cloudpack/common-types';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport fsPromises from 'fs/promises';\nimport { JSDOM } from 'jsdom';\nimport path from 'path';\nimport { pathToFileURL } from 'url';\nimport type { RenderRouteFunction } from '../types/RenderRouteFunction.js';\nimport type { RenderRouteOptions } from '../types/RenderRouteOptions.js';\nimport type { CompleteRenderRouteResult, RenderRouteResult } from '../types/RenderRouteResult.js';\nimport type { RenderRouteScript } from '../types/RenderRouteScript.js';\nimport { getDefaultHtmlResponse } from './getDefaultHtmlResponse.js';\nimport { getHtmlErrorResponse } from './getHtmlErrorResponse.js';\n\nexport type RouteInternal = RenderedRoute & { isDefaultFallback?: boolean };\n\n/**\n * Get the response for the given route. If the route has a custom render script, use that.\n * Returns an error response if the file referenced by the script doesn't exist or throws an error.\n */\nexport async function renderRoute(options: RenderRouteOptions): Promise<CompleteRenderRouteResult> {\n const { route, session, req } = options;\n\n // Get the request path and extension (the URL.pathname conversion gets rid of any query or hash)\n const requestPath = makeUrl(req.url, options.baseUrl).pathname;\n const requestExt = path.extname(requestPath);\n // Determine whether HTML is (probably) an acceptable response type (can be refined later if needed).\n // In theory we should be able to use req.accepts() but not all requests set the accept header.\n const isHtmlAcceptable =\n (!requestExt || requestExt.startsWith('.htm')) && !req.xhr && isHtmlType(req.headers.accept || '*/*');\n\n // Get an initial result from either the render script or default handler.\n let rawResult: RenderRouteResult;\n const renderScriptPath = route.renderScript && path.resolve(session.appPath, route.renderScript);\n if (renderScriptPath) {\n const scriptExt = path.extname(renderScriptPath).toLowerCase();\n if (scriptExt === '.html' || scriptExt === '.htm') {\n rawResult = await readStaticHtml(renderScriptPath);\n } else {\n rawResult = await renderCustomScript({ ...options, renderScriptPath });\n }\n } else {\n rawResult = await getDefaultHtmlResponse(options);\n }\n\n const result: CompleteRenderRouteResult = {\n contentType: 'text/html',\n statusCode: 200,\n ...(typeof rawResult === 'string' ? { content: rawResult } : rawResult),\n };\n\n // If it's HTML and a success statusCode, inject the import map and appropriate scripts.\n if (result.statusCode === 200 && isHtmlType(result.contentType)) {\n // First verify that we're not accidentally returning HTML if a different file type is requested.\n // This could happen for overly broad route matches such as '*', or if no routes are configured.\n if (!isHtmlAcceptable) {\n const renderer = route.renderScript ? `renderScript \"${renderScriptPath}\"` : 'the default renderer';\n const content = (route as RouteInternal).isDefaultFallback\n ? // no routes configured\n `Cloudpack's default route can only return HTML, but this appears to be a non-HTML request. ` +\n `Please add a route under devServer.routes in the cloudpack config.`\n : // route with or without custom renderer\n `Route \"${route.match}\" with ${renderer} returned HTML, but this appears to be a non-HTML request. ` +\n `This is likely a misconfiguration of devServer.routes in the cloudpack config.`;\n return { statusCode: 500, contentType: 'text/plain', content };\n }\n\n // Inject the import map and scripts.\n injectScripts(options, result);\n }\n\n return result;\n}\n\nfunction isHtmlType(acceptOrContentType: string) {\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\n return acceptOrContentType\n .split(',')\n .map((s) => s.split(';')[0].trim())\n .some((mime) => mime === '*/*' || /xml|x?html/i.test(mime) || /^(text|application)\\/\\*$/.test(mime));\n}\n\n/**\n * Load the default export from a JS file passed as the `renderScript` in a route,\n * and return either the result of running the function, or an error page if something fails.\n */\nasync function renderCustomScript(\n params: RenderRouteOptions & { renderScriptPath: string },\n): Promise<RenderRouteResult> {\n const { renderScriptPath, ...options } = params;\n // Get the html factory function from a script default export.\n const renderScriptUrl = pathToFileURL(renderScriptPath).toString();\n\n // Note: because there isn't a way to purge the require cache, we need to add a cache breaker query param to the\n // script path to ensure we get the latest version of the script. This could be improved by using the git hash of\n // the file if it exists, or a hash of the content, or even the timestamp of the file.\n let cacheBreakerQueryParam = `?t=${Date.now()}`;\n try {\n const { mtime } = await fsPromises.stat(renderScriptPath);\n cacheBreakerQueryParam = `?t=${mtime.getTime()}`;\n } catch {\n /* no-op */\n }\n\n // Try importing the script\n let createHtml: RenderRouteFunction | undefined;\n let errorMessage: string | undefined;\n try {\n const importResult = ((await import(renderScriptUrl + cacheBreakerQueryParam)) as RenderRouteScript).default;\n if (typeof importResult === 'function') {\n createHtml = importResult;\n } else {\n errorMessage = `The render script at \"${renderScriptPath}\" does not export a default function.`;\n }\n } catch (e) {\n errorMessage = `Error importing render script at \"${renderScriptUrl}\":\\n${(e as Error).stack || e}`;\n }\n\n if (createHtml) {\n // Try running the script\n try {\n return await createHtml(options);\n } catch (e) {\n errorMessage = `Error running render script at \"${renderScriptPath}\":\\n${(e as Error).stack || e}`;\n }\n }\n\n // Return an error page. Doing this instead of returning a default or empty response ensures that\n // the user is aware of any configuration issues.\n errorMessage ??= `Unknown error loading render script at \"${renderScriptPath}\".`;\n console.error(errorMessage);\n return getHtmlErrorResponse(errorMessage);\n}\n\n/**\n * Modify the HTML response by injecting the import map, inline scripts, and entry/overlay scripts.\n *\n * Note that this just logs an error rather than returning an error response if something fails, for now.\n */\nfunction injectScripts(options: RenderRouteOptions, result: CompleteRenderRouteResult): void {\n const { route, overlayScript, entryScript, inlineScripts, importMap } = options;\n let jsdom: JSDOM;\n try {\n jsdom = new JSDOM(result.content, { contentType: result.contentType } as ConstructorParameters<typeof JSDOM>[1]);\n } catch (e) {\n // Trying to write a test for the above, it seemed very permissive, but catch just in case\n console.error(`Error parsing html response for rendering route \"${route.match}\":\\n${(e as Error).stack || e}`);\n return;\n }\n\n try {\n const { document } = jsdom.window;\n\n if (entryScript || overlayScript) {\n // Inject the import map at the top of the head, in case other scripts use it\n addScript({ document, type: 'importmap', prepend: true, content: JSON.stringify(importMap, null, 2) });\n }\n\n for (const inlineScript of inlineScripts) {\n addScript({ document, content: inlineScript });\n }\n\n // inject the overlay and entry scripts\n addScript({ document, url: overlayScript });\n addScript({ document, url: entryScript });\n\n result.content = jsdom.serialize();\n } catch (e) {\n console.error(`Error injecting scripts for route \"${route.match}\":\\n${(e as Error).stack || e}`);\n }\n}\n\n/**\n * Helper function to add a script to the document.\n */\nfunction addScript(params: { document: Document; type?: string; prepend?: boolean; url?: string; content?: string }) {\n const { document, type = 'module', prepend, url, content } = params;\n if (!url && !content) {\n return;\n }\n\n const script = document.createElement('script');\n script.type = type;\n if (url) {\n script.src = url;\n } else if (content) {\n script.innerHTML = content;\n }\n\n if (prepend) {\n document.head.prepend(script);\n } else {\n document.head.appendChild(script);\n }\n}\n\n/**\n * Read a static HTML file, or return an error response if the file can't be read.\n */\nasync function readStaticHtml(renderScriptPath: string): Promise<RenderRouteResult> {\n try {\n return (await fsPromises.readFile(renderScriptPath, 'utf8')) || '';\n } catch (e) {\n const message = `Error reading HTML file at \"${renderScriptPath}\":\\n${(e as Error).stack || e}`;\n console.error(message);\n return getHtmlErrorResponse(message);\n }\n}\n"]}
|
package/lib/setHeaders.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setHeaders.d.ts","sourceRoot":"","sources":["../src/setHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGxD;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,GAAG,EAAE,QAAQ,CAAC;IACd,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,gBAAgB,GAAG,MAAM,CAAC,CAAC;CACvF,
|
|
1
|
+
{"version":3,"file":"setHeaders.d.ts","sourceRoot":"","sources":["../src/setHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGxD;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,GAAG,EAAE,QAAQ,CAAC;IACd,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,gBAAgB,GAAG,MAAM,CAAC,CAAC;CACvF,QAWA"}
|
package/lib/setHeaders.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCookies } from './getCookies.js';
|
|
2
2
|
/**
|
|
3
3
|
* Set the Cloudpack headers and cookies in the response.
|
|
4
4
|
*/
|
|
@@ -7,10 +7,9 @@ export function setHeaders(params) {
|
|
|
7
7
|
const { apiServer, bundleServer } = session.urls;
|
|
8
8
|
res.header('Cache-Control', 'no-cache');
|
|
9
9
|
res.header('Access-Control-Allow-Origin', '*');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
res.cookie(cookieNames.bundleServerUrl, bundleServer);
|
|
10
|
+
const cookies = getCookies(session, apiServer, bundleServer);
|
|
11
|
+
for (const [key, value] of Object.entries(cookies)) {
|
|
12
|
+
res.cookie(key, value);
|
|
13
|
+
}
|
|
15
14
|
}
|
|
16
15
|
//# sourceMappingURL=setHeaders.js.map
|
package/lib/setHeaders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setHeaders.js","sourceRoot":"","sources":["../src/setHeaders.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"setHeaders.js","sourceRoot":"","sources":["../src/setHeaders.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAG1B;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAEjD,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAE/C,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IAC7D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["import type { Response } from '@ms-cloudpack/create-express-app';\nimport type { Session } from '@ms-cloudpack/api-server';\nimport { getCookies } from './getCookies.js';\n\n/**\n * Set the Cloudpack headers and cookies in the response.\n */\nexport function setHeaders(params: {\n res: Response;\n session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'sessionVersion' | 'urls'>;\n}) {\n const { res, session } = params;\n const { apiServer, bundleServer } = session.urls;\n\n res.header('Cache-Control', 'no-cache');\n res.header('Access-Control-Allow-Origin', '*');\n\n const cookies = getCookies(session, apiServer, bundleServer);\n for (const [key, value] of Object.entries(cookies)) {\n res.cookie(key, value);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ImportMap } from '@ms-cloudpack/import-map';
|
|
2
|
-
import type { PackageJson,
|
|
2
|
+
import type { PackageJson, RenderedRoute } from '@ms-cloudpack/common-types';
|
|
3
3
|
import type { Request, Response } from '@ms-cloudpack/create-express-app';
|
|
4
4
|
import type { Session } from '@ms-cloudpack/api-server';
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@ import type { Session } from '@ms-cloudpack/api-server';
|
|
|
7
7
|
*/
|
|
8
8
|
export interface RenderRouteOptions {
|
|
9
9
|
session: Session;
|
|
10
|
-
route:
|
|
10
|
+
route: RenderedRoute;
|
|
11
11
|
baseUrl: string;
|
|
12
12
|
definition: PackageJson;
|
|
13
13
|
importMap: ImportMap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderRouteOptions.d.ts","sourceRoot":"","sources":["../../src/types/RenderRouteOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"RenderRouteOptions.d.ts","sourceRoot":"","sources":["../../src/types/RenderRouteOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,WAAW,CAAC;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderRouteOptions.js","sourceRoot":"","sources":["../../src/types/RenderRouteOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap } from '@ms-cloudpack/import-map';\nimport type { PackageJson,
|
|
1
|
+
{"version":3,"file":"RenderRouteOptions.js","sourceRoot":"","sources":["../../src/types/RenderRouteOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap } from '@ms-cloudpack/import-map';\nimport type { PackageJson, RenderedRoute } from '@ms-cloudpack/common-types';\nimport type { Request, Response } from '@ms-cloudpack/create-express-app';\nimport type { Session } from '@ms-cloudpack/api-server';\n\n/**\n * The input options for a `renderScript` custom server render function.\n */\nexport interface RenderRouteOptions {\n session: Session;\n route: RenderedRoute;\n baseUrl: string;\n definition: PackageJson;\n importMap: ImportMap;\n overlayScript: string | undefined;\n entryScript: string | undefined;\n inlineScripts: string[];\n req: Request;\n res: Response;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/app-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "An implementation of the App server for Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/api-server": "^0.44.
|
|
18
|
-
"@ms-cloudpack/bundle-server": "^0.4.
|
|
19
|
-
"@ms-cloudpack/common-types": "^0.
|
|
20
|
-
"@ms-cloudpack/create-express-app": "^1.6.
|
|
21
|
-
"@ms-cloudpack/import-map": "^0.5.
|
|
22
|
-
"@ms-cloudpack/overlay": "^0.17.
|
|
17
|
+
"@ms-cloudpack/api-server": "^0.44.7",
|
|
18
|
+
"@ms-cloudpack/bundle-server": "^0.4.9",
|
|
19
|
+
"@ms-cloudpack/common-types": "^0.6.0",
|
|
20
|
+
"@ms-cloudpack/create-express-app": "^1.6.15",
|
|
21
|
+
"@ms-cloudpack/import-map": "^0.5.6",
|
|
22
|
+
"@ms-cloudpack/overlay": "^0.17.7",
|
|
23
23
|
"@ms-cloudpack/path-string-parsing": "^1.2.2",
|
|
24
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
24
|
+
"@ms-cloudpack/path-utilities": "^2.7.12",
|
|
25
25
|
"@ms-cloudpack/task-reporter": "^0.14.1",
|
|
26
26
|
"jsdom": "^24.0.0"
|
|
27
27
|
},
|