@ms-cloudpack/cli 0.23.14 → 0.23.15
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/commands/start/appServer/createRoutes.d.ts +14 -0
- package/lib/commands/start/appServer/createRoutes.js +69 -0
- package/lib/commands/start/appServer/createRoutes.js.map +1 -0
- package/lib/commands/start/appServer/error.d.ts +1 -0
- package/lib/commands/start/appServer/error.js +4 -0
- package/lib/commands/start/appServer/error.js.map +1 -0
- package/lib/commands/start/appServer/exitIfPortUnavailable.d.ts +4 -0
- package/lib/commands/start/appServer/exitIfPortUnavailable.js +15 -0
- package/lib/commands/start/appServer/exitIfPortUnavailable.js.map +1 -0
- package/lib/commands/start/appServer/getDefaultHtmlResponse.d.ts +5 -0
- package/lib/commands/start/appServer/getDefaultHtmlResponse.js +18 -0
- package/lib/commands/start/appServer/getDefaultHtmlResponse.js.map +1 -0
- package/lib/commands/start/appServer/getHtmlResponse.d.ts +5 -0
- package/lib/commands/start/appServer/getHtmlResponse.js +108 -0
- package/lib/commands/start/appServer/getHtmlResponse.js.map +1 -0
- package/lib/commands/start/appServer/handleSessionVersion.d.ts +7 -0
- package/lib/commands/start/appServer/handleSessionVersion.js +12 -0
- package/lib/commands/start/appServer/handleSessionVersion.js.map +1 -0
- package/lib/commands/start/{inlineScripts.d.ts → appServer/inlineScripts.d.ts} +0 -0
- package/lib/commands/start/{inlineScripts.js → appServer/inlineScripts.js} +0 -0
- package/lib/commands/start/appServer/inlineScripts.js.map +1 -0
- package/lib/commands/start/appServer/log.d.ts +1 -0
- package/lib/commands/start/appServer/log.js +5 -0
- package/lib/commands/start/appServer/log.js.map +1 -0
- package/lib/commands/start/appServer/setHeaders.d.ts +10 -0
- package/lib/commands/start/appServer/setHeaders.js +13 -0
- package/lib/commands/start/appServer/setHeaders.js.map +1 -0
- package/lib/commands/start/{startAppServer.d.ts → appServer/startAppServer.d.ts} +5 -5
- package/lib/commands/start/appServer/startAppServer.js +48 -0
- package/lib/commands/start/appServer/startAppServer.js.map +1 -0
- package/lib/commands/start/createBundleTask.js +0 -1
- package/lib/commands/start/createBundleTask.js.map +1 -1
- package/lib/commands/start/start.js +12 -3
- package/lib/commands/start/start.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/types.d.ts +65 -2
- package/package.json +5 -3
- package/CHANGELOG.json +0 -2199
- package/CHANGELOG.md +0 -819
- package/lib/commands/start/inlineScripts.js.map +0 -1
- package/lib/commands/start/startAppServer.js +0 -155
- package/lib/commands/start/startAppServer.js.map +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PackageJson } from '@ms-cloudpack/bundler-types';
|
|
2
|
+
import type { Express } from '@ms-cloudpack/create-express-app';
|
|
3
|
+
import type { ApiServer, BundleServer, CloudpackConfig, Session } from '../../../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates the routes for the express app, considering how the config is defined.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createRoutes({ app, session, definition, bundleServer, apiServer, config, }: {
|
|
8
|
+
app: Express;
|
|
9
|
+
session: Session;
|
|
10
|
+
definition: PackageJson;
|
|
11
|
+
bundleServer: BundleServer;
|
|
12
|
+
apiServer: ApiServer;
|
|
13
|
+
config: CloudpackConfig;
|
|
14
|
+
}): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { express } from '@ms-cloudpack/create-express-app';
|
|
2
|
+
import { createImportMap } from '@ms-cloudpack/package-utilities';
|
|
3
|
+
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { error } from './error.js';
|
|
6
|
+
import { getHtmlResponse } from './getHtmlResponse.js';
|
|
7
|
+
import { handleSessionVersion } from './handleSessionVersion.js';
|
|
8
|
+
import { inlineScripts } from './inlineScripts.js';
|
|
9
|
+
import { log } from './log.js';
|
|
10
|
+
import { setHeaders } from './setHeaders.js';
|
|
11
|
+
/**
|
|
12
|
+
* Creates the routes for the express app, considering how the config is defined.
|
|
13
|
+
*/
|
|
14
|
+
export function createRoutes({ app, session, definition, bundleServer, apiServer, config, }) {
|
|
15
|
+
const routes = [...(config.devServer?.routes || [])];
|
|
16
|
+
const hasDefaultRoute = routes.some((route) => route.match === '*' || route.match === '/');
|
|
17
|
+
if (!hasDefaultRoute) {
|
|
18
|
+
routes.push({
|
|
19
|
+
match: '*',
|
|
20
|
+
exportEntry: '.',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
for (const route of routes) {
|
|
24
|
+
if (route.staticPath) {
|
|
25
|
+
app.use(route.match, express.static(path.resolve(session.appPath, route.staticPath)));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
app.get(route.match, (req, res) => {
|
|
29
|
+
(async () => {
|
|
30
|
+
// Build the import map if it hasn't been built yet for this session version.
|
|
31
|
+
const sessionVersion = handleSessionVersion(session, req);
|
|
32
|
+
const importMap = session.getImportMap() ||
|
|
33
|
+
session.setImportMap(await createImportMap(session.resolveMap, bundleServer.url, {
|
|
34
|
+
sessionVersion,
|
|
35
|
+
targetVersions: session.targetVersions,
|
|
36
|
+
}));
|
|
37
|
+
// Parse the request path, extension, grab the overlay script path.
|
|
38
|
+
const requestPath = slash(req.path.substring(1));
|
|
39
|
+
const requestExt = path.extname(requestPath);
|
|
40
|
+
const overlayScript = importMap.imports['@ms-cloudpack/overlay'];
|
|
41
|
+
const entryScript =
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
43
|
+
route.exportEntry && importMap.imports[slash(path.join(definition.name, route.exportEntry))];
|
|
44
|
+
// Set the apppropriate Cloudpack headers/cookies in the response.
|
|
45
|
+
// TODO: setting the headers here prohibits cases where the page rendering is owned by existing server code
|
|
46
|
+
// that can only accept changing the scripts. We should consider moving to a model where an initial script
|
|
47
|
+
// fetch loads the import map and sets Cloudpack settings in local storage rather than headers/cookies.
|
|
48
|
+
setHeaders({ res, session, apiServer });
|
|
49
|
+
const { html, statusCode } = await getHtmlResponse({
|
|
50
|
+
route,
|
|
51
|
+
importMap,
|
|
52
|
+
overlayScript,
|
|
53
|
+
entryScript,
|
|
54
|
+
session,
|
|
55
|
+
definition,
|
|
56
|
+
inlineScripts,
|
|
57
|
+
});
|
|
58
|
+
// Send the result.
|
|
59
|
+
res.status(statusCode).send(html).end();
|
|
60
|
+
log(`App server: Request: ${requestPath}, ext: ${requestExt}`);
|
|
61
|
+
})().catch((err) => {
|
|
62
|
+
error(err?.stack || err);
|
|
63
|
+
res.status(500).send(`Error loading app: ${err}`);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=createRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/createRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,MAAM,GAQP;IACC,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS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AAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;oBACjE,MAAM,WAAW;oBACf,oEAAoE;oBACpE,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;oBAEhG,kEAAkE;oBAClE,2GAA2G;oBAC3G,0GAA0G;oBAC1G,uGAAuG;oBACvG,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;oBAExC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,eAAe,CAAC;wBACjD,KAAK;wBACL,SAAS;wBACT,aAAa;wBACb,WAAW;wBACX,OAAO;wBACP,UAAU;wBACV,aAAa;qBACd,CAAC,CAAC;oBAEH,mBAAmB;oBACnB,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;oBAExC,GAAG,CAAC,wBAAwB,WAAW,UAAU,UAAU,EAAE,CAAC,CAAC;gBACjE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACjB,KAAK,CAAE,GAAa,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;oBACpC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;gBACpD,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;KACF;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function error(...messages: unknown[]): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/error.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,GAAG,QAAmB;IAC1C,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { error } from './error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Report the error and exit if the port is already in use.
|
|
4
|
+
*/
|
|
5
|
+
export function exitIfPortUnavailable(err, projectName, ports) {
|
|
6
|
+
const portRange = typeof ports === 'number' ? [ports] : ports;
|
|
7
|
+
if (err instanceof Error && err.message === 'Specified port not available') {
|
|
8
|
+
const portNeedsPrivileges = portRange.some((port) => port < 1024)
|
|
9
|
+
? '\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'
|
|
10
|
+
: '';
|
|
11
|
+
error(`Cloudpack could not start "${projectName}" because no port from the allowed list was available: ${portRange.join(', ')}. Close other programs and try again.`, portNeedsPrivileges);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=exitIfPortUnavailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitIfPortUnavailable.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/exitIfPortUnavailable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY,EAAE,WAAmB,EAAE,KAAwB;IAC/F,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,KAAK,8BAA8B,EAAE;QAC1E,MAAM,mBAAmB,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;YAC/D,CAAC,CAAC,iKAAiK;YACnK,CAAC,CAAC,EAAE,CAAC;QACP,KAAK,CACH,8BAA8B,WAAW,0DAA0D,SAAS,CAAC,IAAI,CAC/G,IAAI,CACL,uCAAuC,EACxC,mBAAmB,CACpB,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return the default HTML response.
|
|
3
|
+
*/
|
|
4
|
+
export function getDefaultHtmlResponse({ definition }) {
|
|
5
|
+
const { name } = definition;
|
|
6
|
+
return [
|
|
7
|
+
`<!DOCTYPE html>`,
|
|
8
|
+
`<html lang="en">`,
|
|
9
|
+
`<head>`,
|
|
10
|
+
` <title>${name}</title>`,
|
|
11
|
+
`</head>`,
|
|
12
|
+
`<body>`,
|
|
13
|
+
`<div id="root"></div>`,
|
|
14
|
+
`</body>`,
|
|
15
|
+
`</html>`,
|
|
16
|
+
].join('\n');
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=getDefaultHtmlResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDefaultHtmlResponse.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/getDefaultHtmlResponse.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,EAAE,UAAU,EAAqB;IACtE,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IAE5B,OAAO;QACL,iBAAiB;QACjB,kBAAkB;QAClB,QAAQ;QACR,YAAY,IAAI,UAAU;QAC1B,SAAS;QACT,QAAQ;QACR,uBAAuB;QACvB,SAAS;QACT,SAAS;KACV,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CreateHtmlOptions, CreateHtmlResult } from '../../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the HTML response for the given route. If the route has a custom render script, use that.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getHtmlResponse(options: CreateHtmlOptions): Promise<Exclude<CreateHtmlResult, string>>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
import { getDefaultHtmlResponse } from './getDefaultHtmlResponse.js';
|
|
4
|
+
import { JSDOM } from 'jsdom';
|
|
5
|
+
import { inlineScripts } from './inlineScripts.js';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import { error } from './error.js';
|
|
8
|
+
const { stat, readFile } = fs.promises;
|
|
9
|
+
/**
|
|
10
|
+
* Get the HTML response for the given route. If the route has a custom render script, use that.
|
|
11
|
+
*/
|
|
12
|
+
export async function getHtmlResponse(options) {
|
|
13
|
+
const { route, session, overlayScript, entryScript } = options;
|
|
14
|
+
let createHtml = getDefaultHtmlResponse;
|
|
15
|
+
if (route.renderScript) {
|
|
16
|
+
const renderScriptPath = path.resolve(session.appPath, route.renderScript);
|
|
17
|
+
let cacheBreakerQueryParam = `?t=${Date.now()}`;
|
|
18
|
+
try {
|
|
19
|
+
const { mtime } = await stat(path.resolve(session.appPath, route.renderScript));
|
|
20
|
+
cacheBreakerQueryParam = `?t=${mtime.getTime()}`;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* no-op */
|
|
24
|
+
}
|
|
25
|
+
if (isHtml(renderScriptPath)) {
|
|
26
|
+
createHtml = readStaticHtml;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Get the html factory function from a script default export.
|
|
30
|
+
const renderScriptUrl = pathToFileURL(renderScriptPath).toString();
|
|
31
|
+
// Note: because there isn't a way to purge the require cache, we need to add a cache breaker query param to the
|
|
32
|
+
// script path to ensure we get the latest version of the script. This could be improved by using the git hash of
|
|
33
|
+
// the file if it exists, or a hash of the content, or even the timestamp of the file.
|
|
34
|
+
try {
|
|
35
|
+
createHtml = (await import(renderScriptUrl + cacheBreakerQueryParam)).default;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
error(`Error importing render script at "${renderScriptUrl}":`, e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!createHtml) {
|
|
42
|
+
error(`The render script at "${renderScriptPath}" does not export a default function.`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const htmlResult = await createHtml(options);
|
|
46
|
+
let html = typeof htmlResult === 'string' ? htmlResult : htmlResult.html;
|
|
47
|
+
const statusCode = typeof htmlResult === 'string' ? 200 : htmlResult.statusCode || 200;
|
|
48
|
+
try {
|
|
49
|
+
const htmlDocument = new JSDOM(html);
|
|
50
|
+
const { document } = htmlDocument.window;
|
|
51
|
+
// inject the import map.
|
|
52
|
+
if (entryScript || overlayScript) {
|
|
53
|
+
const script = document.createElement('script');
|
|
54
|
+
script.type = 'importmap';
|
|
55
|
+
script.innerHTML = JSON.stringify(session.getImportMap(), null, 2);
|
|
56
|
+
document.head.prepend(script);
|
|
57
|
+
}
|
|
58
|
+
// inject inline scripts.
|
|
59
|
+
for (const inlineScript of inlineScripts) {
|
|
60
|
+
const script = document.createElement('script');
|
|
61
|
+
script.type = 'module';
|
|
62
|
+
script.innerHTML = inlineScript;
|
|
63
|
+
document.head.appendChild(script);
|
|
64
|
+
}
|
|
65
|
+
// inject the overlay script.
|
|
66
|
+
addScript(document.head, overlayScript);
|
|
67
|
+
// inject the entry script.
|
|
68
|
+
addScript(document.head, entryScript);
|
|
69
|
+
html = htmlDocument.serialize();
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
error(`Error parsing html response for rendering route "${route.match}"`, e);
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
html,
|
|
76
|
+
statusCode,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Helper function to add a script to the document.
|
|
81
|
+
*/
|
|
82
|
+
function addScript(parentElement, url) {
|
|
83
|
+
if (url) {
|
|
84
|
+
const script = parentElement.ownerDocument.createElement('script');
|
|
85
|
+
script.type = 'module';
|
|
86
|
+
script.src = url;
|
|
87
|
+
parentElement.appendChild(script);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function isHtml(path) {
|
|
91
|
+
// path has an .htm or .html extension; case insensitive.
|
|
92
|
+
return path.toLowerCase().match(/\.htm(l)?$/) !== null;
|
|
93
|
+
}
|
|
94
|
+
async function readStaticHtml(options) {
|
|
95
|
+
const { route } = options;
|
|
96
|
+
let html = '';
|
|
97
|
+
if (route.renderScript) {
|
|
98
|
+
const htmlPath = path.resolve(options.session.appPath, route.renderScript);
|
|
99
|
+
try {
|
|
100
|
+
html = (await readFile(htmlPath, 'utf8')) || '';
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
error(`Error reading HTML file at "${htmlPath}".`, e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return html;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=getHtmlResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHtmlResponse.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/getHtmlResponse.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;AACvC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA0B;IAC9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AC,CAAC;KAC9E;IAED,OAAO;QACL,IAAI;QACJ,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,aAA0B,EAAE,GAAuB;IACpE,IAAI,GAAG,EAAE;QACP,MAAM,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAEnE,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;QACvB,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;QACjB,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;KACnC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,yDAAyD;IACzD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AACzD,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,OAA0B;IACtD,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1B,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,IAAI,KAAK,CAAC,YAAY,EAAE;QACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAE3E,IAAI;YACF,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;SACjD;QAAC,OAAO,CAAC,EAAE;YACV,KAAK,CAAC,+BAA+B,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;SACvD;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Request } from '@ms-cloudpack/create-express-app';
|
|
2
|
+
import type { Session } from '../../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get the latest refresh version either from the cookie in request or from the session.
|
|
5
|
+
* Update the session with the latest refresh version.
|
|
6
|
+
*/
|
|
7
|
+
export declare function handleSessionVersion(session: Session, req: Request): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the latest refresh version either from the cookie in request or from the session.
|
|
3
|
+
* Update the session with the latest refresh version.
|
|
4
|
+
*/
|
|
5
|
+
export function handleSessionVersion(session, req) {
|
|
6
|
+
const lastSessionVersion = Number(req.headers.cookie
|
|
7
|
+
?.match('(^|;)\\s*' + `cloudpack-sessionVersion-${session.projectName}` + '\\s*=\\s*([^;]+)')
|
|
8
|
+
?.pop() || '0');
|
|
9
|
+
session.incrementSessionVersion(lastSessionVersion);
|
|
10
|
+
return session.getSessionVersion();
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=handleSessionVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleSessionVersion.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/handleSessionVersion.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,GAAY;IACjE,MAAM,kBAAkB,GAAG,MAAM,CAC/B,GAAG,CAAC,OAAO,CAAC,MAAM;QAChB,EAAE,KAAK,CAAC,WAAW,GAAG,4BAA4B,OAAO,CAAC,WAAW,EAAE,GAAG,kBAAkB,CAAC;QAC7F,EAAE,GAAG,EAAE,IAAI,GAAG,CACjB,CAAC;IACF,OAAO,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IAEpD,OAAO,OAAO,CAAC,iBAAiB,EAAE,CAAC;AACrC,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inlineScripts.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/inlineScripts.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B;;;6FAG2F;IAC3F;;;kHAGgH;CACjH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const log: (...messages: unknown[]) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/log.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE;IAC5C,0CAA0C;AAC5C,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Response } from '@ms-cloudpack/create-express-app';
|
|
2
|
+
import type { ApiServer, Session } from '../../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Set the Cloudpack headers and cookies in the response.
|
|
5
|
+
*/
|
|
6
|
+
export declare function setHeaders({ res, session, apiServer }: {
|
|
7
|
+
res: Response;
|
|
8
|
+
session: Session;
|
|
9
|
+
apiServer: ApiServer;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set the Cloudpack headers and cookies in the response.
|
|
3
|
+
*/
|
|
4
|
+
export function setHeaders({ res, session, apiServer }) {
|
|
5
|
+
res.header('Content-Type', 'text/html');
|
|
6
|
+
res.header('Cache-Control', 'no-cache');
|
|
7
|
+
res.header('Access-Control-Allow-Origin', '*');
|
|
8
|
+
res.cookie('cloudpack-session-id', session.id);
|
|
9
|
+
res.cookie('cloudpack-session-sequence', session.sequence);
|
|
10
|
+
res.cookie(`cloudpack-sessionVersion-${session.projectName}`, session.getSessionVersion());
|
|
11
|
+
res.cookie('cloudpack-api-url', apiServer.url);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=setHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setHeaders.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/setHeaders.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAA6D;IAC/G,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAE/C,GAAG,CAAC,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/C,GAAG,CAAC,MAAM,CAAC,4BAA4B,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3D,GAAG,CAAC,MAAM,CAAC,4BAA4B,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC3F,GAAG,CAAC,MAAM,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ApiServer, BundleServer,
|
|
1
|
+
import type { ApiServer, BundleServer, CloudpackConfig, Session } from '../../../types.js';
|
|
2
|
+
import type { PackageJson } from '@ms-cloudpack/bundler-types';
|
|
2
3
|
/**
|
|
3
4
|
* The app server hosts the appropriate routes for the web app, primarily returning html content
|
|
4
5
|
* which loads resources from the bundle server.
|
|
@@ -7,13 +8,12 @@ import type { ApiServer, BundleServer, DevServer, Session } from '../../types.js
|
|
|
7
8
|
* can support whichever routes the app needs, while the bundle server can provide package
|
|
8
9
|
* assets in various forms using its own routing.
|
|
9
10
|
*/
|
|
10
|
-
export declare function startAppServer({ session, bundleServer, apiServer,
|
|
11
|
+
export declare function startAppServer({ session, bundleServer, apiServer, definition, config, }: {
|
|
11
12
|
session: Session;
|
|
13
|
+
definition: PackageJson;
|
|
12
14
|
bundleServer: BundleServer;
|
|
13
15
|
apiServer: ApiServer;
|
|
14
|
-
|
|
15
|
-
devServer?: DevServer;
|
|
16
|
-
};
|
|
16
|
+
config: CloudpackConfig;
|
|
17
17
|
}): Promise<{
|
|
18
18
|
close: () => Promise<void>;
|
|
19
19
|
port: number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createExpressApp, parseHttpsConfig } from '@ms-cloudpack/create-express-app';
|
|
2
|
+
import { createRoutes } from './createRoutes.js';
|
|
3
|
+
import { exitIfPortUnavailable } from './exitIfPortUnavailable.js';
|
|
4
|
+
/**
|
|
5
|
+
* The app server hosts the appropriate routes for the web app, primarily returning html content
|
|
6
|
+
* which loads resources from the bundle server.
|
|
7
|
+
*
|
|
8
|
+
* Separating the app server from the bundle service keeps the routes separate - the app server
|
|
9
|
+
* can support whichever routes the app needs, while the bundle server can provide package
|
|
10
|
+
* assets in various forms using its own routing.
|
|
11
|
+
*/
|
|
12
|
+
export async function startAppServer({ session, bundleServer, apiServer, definition, config = {}, }) {
|
|
13
|
+
const { devServer = {} } = config || {};
|
|
14
|
+
const { https = {} } = devServer;
|
|
15
|
+
// Read the port from the config file or default to array of ports.
|
|
16
|
+
const requireSpecifiedPort = devServer?.port !== undefined;
|
|
17
|
+
const ports = devServer?.port ?? [5000, 5001, 5002, 5003];
|
|
18
|
+
// Directory to serve as plain static assets. Defaults to "public".
|
|
19
|
+
// Can be overridden by setting the 'publicDir' option in the cloudpack config.
|
|
20
|
+
// const publicDir = path.resolve(devServer.publicPath ?? 'public');
|
|
21
|
+
try {
|
|
22
|
+
const { server, protocol, domain, port } = await createExpressApp({
|
|
23
|
+
portRange: ports,
|
|
24
|
+
requireSpecifiedPort,
|
|
25
|
+
hostname: devServer?.domain,
|
|
26
|
+
sslOptions: parseHttpsConfig(https),
|
|
27
|
+
// publicDir,
|
|
28
|
+
setupCallback: (app) => createRoutes({
|
|
29
|
+
app,
|
|
30
|
+
session,
|
|
31
|
+
definition,
|
|
32
|
+
bundleServer,
|
|
33
|
+
apiServer,
|
|
34
|
+
config,
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
close: () => new Promise((resolve, reject) => server.close((err) => (err ? reject(err) : resolve()))),
|
|
39
|
+
port,
|
|
40
|
+
url: `${protocol}://${domain}:${port}`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
exitIfPortUnavailable(err, session.projectName, ports);
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=startAppServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startAppServer.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/startAppServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGtF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,YAAY,EACZ,SAAS,EACT,UAAU,EACV,MAAM,GAAG,EAAqB,GAO/B;IACC,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,IAAK,EAAsB,CAAC;IAC7D,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC;IAEjC,mEAAmE;IACnE,MAAM,oBAAoB,GAAG,SAAS,EAAE,IAAI,KAAK,SAAS,CAAC;IAC3D,MAAM,KAAK,GAAG,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAE1D,mEAAmE;IACnE,+EAA+E;IAC/E,oEAAoE;IAEpE,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,gBAAgB,CAAC;YAChE,SAAS,EAAE,KAAK;YAChB,oBAAoB;YACpB,QAAQ,EAAE,SAAS,EAAE,MAAM;YAC3B,UAAU,EAAE,gBAAgB,CAAC,KAAK,CAAC;YACnC,cAAc;YACd,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CACrB,YAAY,CAAC;gBACX,GAAG;gBACH,OAAO;gBACP,UAAU;gBACV,YAAY;gBACZ,SAAS;gBACT,MAAM;aACP,CAAC;SACL,CAAC,CAAC;QAEH,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC3G,IAAI;YACJ,GAAG,EAAE,GAAG,QAAQ,MAAM,MAAM,IAAI,IAAI,EAAE;SACvC,CAAC;KACH;IAAC,OAAO,GAAY,EAAE;QACrB,qBAAqB,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACvD,MAAM,GAAG,CAAC;KACX;AACH,CAAC"}
|
|
@@ -16,7 +16,6 @@ export function createBundleTask(bundleRequest, options) {
|
|
|
16
16
|
watch: !isExternal,
|
|
17
17
|
async execute() {
|
|
18
18
|
let bundleResult = bundleRequest;
|
|
19
|
-
log(`Finished ensureDir: "${packageName}@${version}"`);
|
|
20
19
|
// If force is set, dispose the existing result.
|
|
21
20
|
if (force && bundleRequest.result?.dispose) {
|
|
22
21
|
bundleRequest.result.dispose();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../../src/commands/start/createBundleTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,IAAI,MAAM,MAAM,CAA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,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;SAC7E;QACD,GAAG,CAAC,aAAa,aAAa,CAAC,WAAW,IAAI,aAAa,CAAC,OAAO,GAAG,CAAC,CAAC;KACzE;SAAM;QACL,GAAG,CAAC,8BAA8B,aAAa,CAAC,WAAW,IAAI,aAAa,CAAC,OAAO,GAAG,CAAC,CAAC;KAC1F;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { readJson } from '@ms-cloudpack/json-utilities';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { createSession } from './createSession.js';
|
|
5
5
|
import { startBundleServer } from './startBundleServer.js';
|
|
6
|
-
import { startAppServer } from './startAppServer.js';
|
|
6
|
+
import { startAppServer } from './appServer/startAppServer.js';
|
|
7
7
|
import { openBrowser } from './openBrowser.js';
|
|
8
8
|
import { startApiServer } from './startApiServer.js';
|
|
9
9
|
import { createPackageOverrideTransform } from '../../common/createPackageOverrideTransform.js';
|
|
@@ -17,6 +17,14 @@ export async function start() {
|
|
|
17
17
|
const devServer = cloudpackConfig?.devServer || {};
|
|
18
18
|
// Initialize package overrides.
|
|
19
19
|
PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(cloudpackConfig));
|
|
20
|
+
// Make sure the package has a valid definition.
|
|
21
|
+
const definition = await PackageDefinitions.getInstance().get(appPath);
|
|
22
|
+
if (!definition) {
|
|
23
|
+
throw new Error(`There was no package.json located at "${appPath}".`);
|
|
24
|
+
}
|
|
25
|
+
if (!definition.name || !definition.version) {
|
|
26
|
+
throw new Error(`The package.json at "${appPath}" did not have a name and/or version.`);
|
|
27
|
+
}
|
|
20
28
|
// Initialize session definition.
|
|
21
29
|
const session = await createSession({ appPath });
|
|
22
30
|
// Start api server for tracking status and handling remote requests.
|
|
@@ -25,11 +33,11 @@ export async function start() {
|
|
|
25
33
|
const bundleServer = await startBundleServer({ session, apiServer });
|
|
26
34
|
const appServer = await startAppServer({
|
|
27
35
|
session,
|
|
36
|
+
definition,
|
|
28
37
|
bundleServer,
|
|
29
38
|
apiServer,
|
|
30
|
-
|
|
39
|
+
config: { devServer },
|
|
31
40
|
});
|
|
32
|
-
let sigintCount = 0;
|
|
33
41
|
const cleanup = async () => {
|
|
34
42
|
for (const server of [bundleServer, appServer, apiServer]) {
|
|
35
43
|
console.log(`Closing server: ${server.url}`);
|
|
@@ -42,6 +50,7 @@ export async function start() {
|
|
|
42
50
|
}
|
|
43
51
|
};
|
|
44
52
|
// Setup cleanup and close things on completion.
|
|
53
|
+
let sigintCount = 0;
|
|
45
54
|
process.on('SIGINT', () => {
|
|
46
55
|
sigintCount++;
|
|
47
56
|
if (sigintCount > 1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/commands/start/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/commands/start/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC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
|
package/lib/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@
|
|
|
3
3
|
* within the "./commands" folder.
|
|
4
4
|
*/
|
|
5
5
|
export declare function start(): Promise<void>;
|
|
6
|
+
export type { ApiServer, BundleRequest, BundleServer, BundleTaskOptions, CloudpackConfig, CreateHtmlFunction, CreateHtmlOptions, CreateHtmlResult, CreateHtmlScript, DevServer, PackageOverride, Route, Session, SessionStats, Task, TaskDescription, TaskEndDescription, TaskError, TaskOptions, TaskStartDescription, Watcher, } from './types.js';
|
package/lib/types.d.ts
CHANGED
|
@@ -150,6 +150,28 @@ export interface PackageOverride {
|
|
|
150
150
|
isInternal?: boolean;
|
|
151
151
|
overrides: PackageJson;
|
|
152
152
|
}
|
|
153
|
+
export interface Route {
|
|
154
|
+
/**
|
|
155
|
+
* The url path part to match. Start paths with a leading slash, e.g. `'/my-route'`. You can also
|
|
156
|
+
* use wildcards (`*`), e.g. `'/my-route/*'` to match all paths starting with `'/my-route'`.
|
|
157
|
+
*/
|
|
158
|
+
match: string;
|
|
159
|
+
/**
|
|
160
|
+
* The path relative to the app root to static assets. If this is provided, renderScript/exportEntry
|
|
161
|
+
* will be ignored.
|
|
162
|
+
*/
|
|
163
|
+
staticPath?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Path to a .js or .html file used for rendering the route. If a script is provided, it must
|
|
166
|
+
* export a default function implementing `CreateHtmlFunction` defined in @ms-cloudpack/cli.
|
|
167
|
+
*/
|
|
168
|
+
renderScript?: string;
|
|
169
|
+
/**
|
|
170
|
+
* The key in the exports map which represents the entry point app script for this route.
|
|
171
|
+
* Default is '.', meaning the main package export key.
|
|
172
|
+
*/
|
|
173
|
+
exportEntry?: string;
|
|
174
|
+
}
|
|
153
175
|
export interface DevServer {
|
|
154
176
|
/**
|
|
155
177
|
* The domain name of the server.
|
|
@@ -171,14 +193,55 @@ export interface DevServer {
|
|
|
171
193
|
https?: HttpsConfig;
|
|
172
194
|
/**
|
|
173
195
|
* If provided, will override where the publicDir is located, relative to the app package folder.
|
|
174
|
-
* Defaults to `./public`.
|
|
196
|
+
* Defaults to `./public`. The same thing can be achieved with `routes`, using route: '*' and
|
|
197
|
+
* staticPath: './public', so the `publicPath` setting may be removed in the future.
|
|
175
198
|
*/
|
|
176
|
-
|
|
199
|
+
publicPath?: string;
|
|
200
|
+
/**
|
|
201
|
+
* If provided, will register routes with the dev server to host various pages.
|
|
202
|
+
*/
|
|
203
|
+
routes?: Route[];
|
|
177
204
|
}
|
|
178
205
|
/**
|
|
179
206
|
* Per-application configuration for Cloudpack.
|
|
180
207
|
*/
|
|
181
208
|
export interface CloudpackConfig {
|
|
209
|
+
/**
|
|
210
|
+
* An array of PackageOverride objects, used to provide overrides for packages without modifying their
|
|
211
|
+
* definitions directly. This is primarily used for providing exports maps for packages that don't have them.
|
|
212
|
+
*/
|
|
182
213
|
packageOverrides?: PackageOverride[];
|
|
214
|
+
/**
|
|
215
|
+
* A set of options for configuring how the dev server works.
|
|
216
|
+
*/
|
|
183
217
|
devServer?: DevServer;
|
|
184
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* The input options for a createHtml custom server render function.
|
|
221
|
+
*/
|
|
222
|
+
export type CreateHtmlOptions = {
|
|
223
|
+
session: Session;
|
|
224
|
+
route: Route;
|
|
225
|
+
definition: PackageJson;
|
|
226
|
+
importMap: ImportMap;
|
|
227
|
+
overlayScript: string | undefined;
|
|
228
|
+
entryScript: string | undefined;
|
|
229
|
+
inlineScripts: string[];
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* The expected result of the createHtml custom server render function.
|
|
233
|
+
*/
|
|
234
|
+
export type CreateHtmlResult = string | {
|
|
235
|
+
html: string;
|
|
236
|
+
statusCode: number;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* A custom server render function that can be used to override the default HTML response.
|
|
240
|
+
*/
|
|
241
|
+
export type CreateHtmlFunction = (options: CreateHtmlOptions) => Promise<CreateHtmlResult> | CreateHtmlResult;
|
|
242
|
+
/**
|
|
243
|
+
* The expected shape of the createHtml custom server render function script.
|
|
244
|
+
*/
|
|
245
|
+
export type CreateHtmlScript = {
|
|
246
|
+
default: CreateHtmlFunction;
|
|
247
|
+
};
|