@ms-cloudpack/app-server 0.17.50 → 0.17.52

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.
@@ -72,20 +72,9 @@ export function createRoutes(options, context) {
72
72
  async function handleRequest(options, context) {
73
73
  const { req, res, definition, route, url } = options;
74
74
  const { session } = context;
75
- const { bundleServer, appServer } = session.urls;
76
- if (!bundleServer) {
77
- throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');
78
- }
79
- if (!appServer) {
80
- throw new Error('The app server URL is not yet set in the session (this is a Cloudpack bug).');
81
- }
82
75
  // Build the import map if it hasn't been built yet for this session version.
83
76
  // (TS can't infer that urls.bundleServer is set on session from a check above.)
84
- const importMap = (session.importMap ??= await createImportMap({
85
- ...context,
86
- ...session,
87
- urls: { bundleServer, appServer },
88
- }));
77
+ const importMap = (session.importMap ??= await createImportMap(context));
89
78
  // For production mode, no overlay script.
90
79
  const overlayScript = session.config.mode !== 'production' ? importMap.imports['@ms-cloudpack/overlay'] : undefined;
91
80
  // Get all entry scripts for the route.
@@ -1 +1 @@
1
- {"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,aAAa,GAMd,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,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EA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AAC;QACb,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;IAC1F,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,wBAAwB,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type { Context } from '@ms-cloudpack/api-server';\nimport {\n isBootstrapRoute,\n isProxyRoute,\n isRedirectRoute,\n isRenderedRoute,\n isStaticRoute,\n type BootstrapRoute,\n type PackageJson,\n type RenderedRoute,\n type ExpandedRenderFunctionResult,\n type RequestHandler,\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 } from './renderRoute/renderRoute.js';\nimport { renderBootstrapRoute } from './renderBootstrapRoute.js';\nimport { createPageSessionContext } from './createPageSessionContext.js';\nimport { parseRouteMatch } from './parseRouteMatch.js';\nimport { createProxyMiddleware } from 'http-proxy-middleware';\n\ninterface CreateRoutesOptions {\n app: Express;\n /** Base app server URL, including the port */\n url: string;\n /** package.json for the app */\n definition: PackageJson;\n}\n\ntype CreateRoutesContext = Pick<Context, 'packages' | 'packageHashes' | 'session'>;\n\n/** Express middleware that will match the domain to continue the route execution. */\nfunction matchDomain(domain?: RegExp): RequestHandler {\n return (req, _, next) => {\n if (!domain || domain.test(req.hostname)) {\n return next();\n }\n\n // Jump to next route.\n return next('route');\n };\n}\n\n/**\n * Creates the routes for the express app based on the config.\n */\nexport function createRoutes(options: CreateRoutesOptions, context: CreateRoutesContext): void {\n const { app, ...otherOptions } = options;\n const { session } = context;\n const { config } = session;\n const { appPath } = config;\n const routes = [...(session.config.routes || [])];\n\n if (!options.definition.name) {\n throw new Error('Name field is required in the package.json file.');\n }\n\n if (!routes.length) {\n // If no routes have been defined, register a default (no path) route only.\n // This will render default HTML which includes the app's default path ('.') from the import map.\n routes.push({\n match: '/',\n // sourcePath and requestPath are required by types but unused in this case.\n entry: [{ importPath: '.', sourcePath: '' }],\n });\n }\n\n for (const route of routes) {\n const matches = Array.isArray(route.match) ? route.match : [route.match];\n\n for (const match of matches) {\n const { pathMatch, domainMatch } = parseRouteMatch(match);\n\n if (isStaticRoute(route)) {\n app.use(pathMatch, matchDomain(domainMatch), express.static(path.resolve(appPath, route.staticPath)));\n } else if (isRedirectRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (req, res) => {\n res.redirect(route.redirectTo);\n });\n } else if (isRenderedRoute(route) || isBootstrapRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (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 if (isProxyRoute(route)) {\n app.use(\n pathMatch,\n matchDomain(domainMatch),\n createProxyMiddleware({ target: route.proxyTo, ...route }) as RequestHandler,\n );\n } else {\n throw new Error(`Unknown route: ${JSON.stringify(route)}`);\n }\n }\n }\n}\n\nasync function handleRequest(\n options: Omit<CreateRoutesOptions, 'app'> & {\n req: Request;\n res: Response;\n route: RenderedRoute | BootstrapRoute;\n },\n context: CreateRoutesContext,\n): Promise<void> {\n const { req, res, definition, route, url } = options;\n const { session } = context;\n const { bundleServer, appServer } = session.urls;\n\n if (!bundleServer) {\n throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');\n }\n\n if (!appServer) {\n throw new Error('The app 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({\n ...context,\n ...session,\n urls: { bundleServer, appServer },\n }));\n\n // For production mode, no overlay script.\n const overlayScript = session.config.mode !== 'production' ? importMap.imports['@ms-cloudpack/overlay'] : undefined;\n\n // Get all entry scripts for the route.\n const entryScripts = route.entry?.map(\n (entry) => importMap.imports[slash(path.join(definition.name, entry.importPath))],\n );\n\n const pageSessionContextScript =\n `window.__cloudpack ??= {};\\n` +\n `window.__cloudpack.pageSessionContext = ${JSON.stringify(createPageSessionContext(session, req.path))};`;\n\n // Add the pageSessionContext to the top of the inlineScripts\n const inlineScripts = [pageSessionContextScript, ...(await getInlineScripts())];\n\n // Set the appropriate Cloudpack headers in the response.\n res.header('Cache-Control', 'no-cache');\n res.header('Access-Control-Allow-Origin', '*');\n\n let rendered: ExpandedRenderFunctionResult | null;\n\n if (isBootstrapRoute(route)) {\n // Render the bootstrap script\n rendered = await renderBootstrapRoute({\n session,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n requestPath: req.path,\n });\n } else {\n // HTML or custom script rendering\n rendered = await renderRoute({\n ...options,\n session,\n baseUrl: url,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n });\n }\n\n if (rendered) {\n res.type(rendered.contentType).status(rendered.statusCode).send(rendered.content).end();\n }\n\n console.debug(`App server: Request: ${req.path}`);\n}\n"]}
1
+ {"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,aAAa,GAMd,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,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AI,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type { Context } from '@ms-cloudpack/api-server';\nimport {\n isBootstrapRoute,\n isProxyRoute,\n isRedirectRoute,\n isRenderedRoute,\n isStaticRoute,\n type BootstrapRoute,\n type PackageJson,\n type RenderedRoute,\n type ExpandedRenderFunctionResult,\n type RequestHandler,\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 } from './renderRoute/renderRoute.js';\nimport { renderBootstrapRoute } from './renderBootstrapRoute.js';\nimport { createPageSessionContext } from './createPageSessionContext.js';\nimport { parseRouteMatch } from './parseRouteMatch.js';\nimport { createProxyMiddleware } from 'http-proxy-middleware';\n\ninterface CreateRoutesOptions {\n app: Express;\n /** Base app server URL, including the port */\n url: string;\n /** package.json for the app */\n definition: PackageJson;\n}\n\ntype CreateRoutesContext = Pick<Context, 'packages' | 'packageHashes' | 'session'>;\n\n/** Express middleware that will match the domain to continue the route execution. */\nfunction matchDomain(domain?: RegExp): RequestHandler {\n return (req, _, next) => {\n if (!domain || domain.test(req.hostname)) {\n return next();\n }\n\n // Jump to next route.\n return next('route');\n };\n}\n\n/**\n * Creates the routes for the express app based on the config.\n */\nexport function createRoutes(options: CreateRoutesOptions, context: CreateRoutesContext): void {\n const { app, ...otherOptions } = options;\n const { session } = context;\n const { config } = session;\n const { appPath } = config;\n const routes = [...(session.config.routes || [])];\n\n if (!options.definition.name) {\n throw new Error('Name field is required in the package.json file.');\n }\n\n if (!routes.length) {\n // If no routes have been defined, register a default (no path) route only.\n // This will render default HTML which includes the app's default path ('.') from the import map.\n routes.push({\n match: '/',\n // sourcePath and requestPath are required by types but unused in this case.\n entry: [{ importPath: '.', sourcePath: '' }],\n });\n }\n\n for (const route of routes) {\n const matches = Array.isArray(route.match) ? route.match : [route.match];\n\n for (const match of matches) {\n const { pathMatch, domainMatch } = parseRouteMatch(match);\n\n if (isStaticRoute(route)) {\n app.use(pathMatch, matchDomain(domainMatch), express.static(path.resolve(appPath, route.staticPath)));\n } else if (isRedirectRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (req, res) => {\n res.redirect(route.redirectTo);\n });\n } else if (isRenderedRoute(route) || isBootstrapRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (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 if (isProxyRoute(route)) {\n app.use(\n pathMatch,\n matchDomain(domainMatch),\n createProxyMiddleware({ target: route.proxyTo, ...route }) as RequestHandler,\n );\n } else {\n throw new Error(`Unknown route: ${JSON.stringify(route)}`);\n }\n }\n }\n}\n\nasync function handleRequest(\n options: Omit<CreateRoutesOptions, 'app'> & {\n req: Request;\n res: Response;\n route: RenderedRoute | BootstrapRoute;\n },\n context: CreateRoutesContext,\n): Promise<void> {\n const { req, res, definition, route, url } = options;\n const { session } = context;\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));\n\n // For production mode, no overlay script.\n const overlayScript = session.config.mode !== 'production' ? importMap.imports['@ms-cloudpack/overlay'] : undefined;\n\n // Get all entry scripts for the route.\n const entryScripts = route.entry?.map(\n (entry) => importMap.imports[slash(path.join(definition.name, entry.importPath))],\n );\n\n const pageSessionContextScript =\n `window.__cloudpack ??= {};\\n` +\n `window.__cloudpack.pageSessionContext = ${JSON.stringify(createPageSessionContext(session, req.path))};`;\n\n // Add the pageSessionContext to the top of the inlineScripts\n const inlineScripts = [pageSessionContextScript, ...(await getInlineScripts())];\n\n // Set the appropriate Cloudpack headers in the response.\n res.header('Cache-Control', 'no-cache');\n res.header('Access-Control-Allow-Origin', '*');\n\n let rendered: ExpandedRenderFunctionResult | null;\n\n if (isBootstrapRoute(route)) {\n // Render the bootstrap script\n rendered = await renderBootstrapRoute({\n session,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n requestPath: req.path,\n });\n } else {\n // HTML or custom script rendering\n rendered = await renderRoute({\n ...options,\n session,\n baseUrl: url,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n });\n }\n\n if (rendered) {\n res.type(rendered.contentType).status(rendered.statusCode).send(rendered.content).end();\n }\n\n console.debug(`App server: Request: ${req.path}`);\n}\n"]}
@@ -1,6 +1,5 @@
1
- import type { Session } from '@ms-cloudpack/api-server';
2
1
  import type { BootstrapInput } from '@ms-cloudpack/common-types-browser';
3
- import type { ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';
2
+ import type { ExpandedRenderFunctionResult, Session } from '@ms-cloudpack/common-types';
4
3
  /**
5
4
  * Render a route with a JS script that will set up and call `window.__cloudpack.bootstrap()`.
6
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"renderBootstrapRoute.d.ts","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAE/E;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,oBAAoB,CAAC,GAAG;IACnD,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,MAAM,CAAC,CAAC;CACpE,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAC1B,OAAO,CAAC,4BAA4B,CAAC,CAmBvC"}
1
+ {"version":3,"file":"renderBootstrapRoute.d.ts","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,4BAA4B,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAExF;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,oBAAoB,CAAC,GAAG;IACnD,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,MAAM,CAAC,CAAC;CACpE,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAC1B,OAAO,CAAC,4BAA4B,CAAC,CAmBvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"renderBootstrapRoute.js","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAI9E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAE2B;IAE3B,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;IAElD,mFAAmF;IACnF,wDAAwD;IACxD,MAAM,qBAAqB,GAAG,CAAC,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAE1F,oCAAoC;IACpC,6CAA6C;IAC7C,MAAM,OAAO,GAAG;MACZ,qBAAqB;mCACQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;GACrD,CAAC;IAEF,OAAO;QACL,OAAO;QACP,WAAW,EAAE,wBAAwB;QACrC,UAAU,EAAE,GAAG;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import type { Session } from '@ms-cloudpack/api-server';\nimport { getBoostrapInlineScript } from './inlineScripts/getInlineScripts.js';\nimport type { BootstrapInput } from '@ms-cloudpack/common-types-browser';\nimport type { ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';\n\n/**\n * Render a route with a JS script that will set up and call `window.__cloudpack.bootstrap()`.\n */\nexport async function renderBootstrapRoute(\n params: Omit<BootstrapInput, 'pageSessionContext'> & {\n session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'urls'>;\n } & { requestPath: string },\n): Promise<ExpandedRenderFunctionResult> {\n const { session, requestPath, ...input } = params;\n\n // TS adds \"export {}\" when transpiling bootstrap.inline.ts due to isolatedModules.\n // Remove this since the bootstrap script cannot be ESM.\n const bootstrapInlineScript = (await getBoostrapInlineScript()).replace('export {};', '');\n\n // Inject the boostrap inline script\n // Call the bootstrap function with the input\n const content = `\n ${bootstrapInlineScript}\n window.__cloudpack.bootstrap(${JSON.stringify(input)});\n `;\n\n return {\n content,\n contentType: 'application/javascript',\n statusCode: 200,\n };\n}\n"]}
1
+ {"version":3,"file":"renderBootstrapRoute.js","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAI9E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAE2B;IAE3B,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;IAElD,mFAAmF;IACnF,wDAAwD;IACxD,MAAM,qBAAqB,GAAG,CAAC,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAE1F,oCAAoC;IACpC,6CAA6C;IAC7C,MAAM,OAAO,GAAG;MACZ,qBAAqB;mCACQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;GACrD,CAAC;IAEF,OAAO;QACL,OAAO;QACP,WAAW,EAAE,wBAAwB;QACrC,UAAU,EAAE,GAAG;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import { getBoostrapInlineScript } from './inlineScripts/getInlineScripts.js';\nimport type { BootstrapInput } from '@ms-cloudpack/common-types-browser';\nimport type { ExpandedRenderFunctionResult, Session } from '@ms-cloudpack/common-types';\n\n/**\n * Render a route with a JS script that will set up and call `window.__cloudpack.bootstrap()`.\n */\nexport async function renderBootstrapRoute(\n params: Omit<BootstrapInput, 'pageSessionContext'> & {\n session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'urls'>;\n } & { requestPath: string },\n): Promise<ExpandedRenderFunctionResult> {\n const { session, requestPath, ...input } = params;\n\n // TS adds \"export {}\" when transpiling bootstrap.inline.ts due to isolatedModules.\n // Remove this since the bootstrap script cannot be ESM.\n const bootstrapInlineScript = (await getBoostrapInlineScript()).replace('export {};', '');\n\n // Inject the boostrap inline script\n // Call the bootstrap function with the input\n const content = `\n ${bootstrapInlineScript}\n window.__cloudpack.bootstrap(${JSON.stringify(input)});\n `;\n\n return {\n content,\n contentType: 'application/javascript',\n statusCode: 200,\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { PartialContext } from '@ms-cloudpack/api-server';
2
- import { type BundleServer, type BundleServerContext, type BundleServerOptions } from '@ms-cloudpack/bundle-server';
1
+ import type { Context } from '@ms-cloudpack/api-server';
2
+ import { type BundleServer, type BundleServerOptions } from '@ms-cloudpack/bundle-server';
3
3
  import type { PackageJson } from '@ms-cloudpack/common-types';
4
4
  import type { Server } from 'http';
5
5
  import type { AppServer } from './types/AppServer.js';
@@ -24,7 +24,7 @@ export declare function startServers(options: {
24
24
  /** Custom port for the app server (probably from CLI options) */
25
25
  port?: number | number[];
26
26
  bundleServerOptions: BundleServerOptions;
27
- }, context: PartialContext<'reporter', 'config' | 'projectName'> & BundleServerContext): Promise<{
27
+ }, context: Context): Promise<{
28
28
  appServer: AppServer;
29
29
  bundleServer?: BundleServer;
30
30
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"startServers.d.ts","sourceRoot":"","sources":["../src/startServers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,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CAAC,CAAC;QACvE,CAAC;QAED,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;QAEhD,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,eAAe,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAExE,OAAO;YACL,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE;YACpC,YAAY;SACb,CAAC;IACJ,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,4BAA4B,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1F,0BAA0B,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAE5D,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["import type { PartialContext } from '@ms-cloudpack/api-server';\nimport {\n handleBundleRequest,\n startBundleServer,\n type BundleServer,\n type BundleServerContext,\n type BundleServerOptions,\n} from '@ms-cloudpack/bundle-server';\nimport type { PackageJson } from '@ms-cloudpack/common-types';\nimport { createExpressApp, getDomain } from '@ms-cloudpack/create-express-app';\nimport { combinedServerBundleRequestPrefix } from '@ms-cloudpack/import-map';\nimport { cyan } from '@ms-cloudpack/task-reporter';\nimport type { Server } from 'http';\nimport { createRoutes } from './createRoutes.js';\nimport { handleErrorPortUnavailable } from './handleErrorPortUnavailable.js';\nimport type { AppServer } from './types/AppServer.js';\n\n/**\n * Start the app server, and (usually) the bundle server (but see below).\n *\n * The app server hosts the appropriate routes for the web app, primarily returning html content\n * which loads resources from the bundle server.\n *\n * Separating the app server from the bundle service keeps the routes separate - the app server\n * can support whichever routes the app needs, while the bundle server can provide package\n * assets in various forms using its own routing.\n *\n * Exception: some projects need the bundle server and app server on the same origin for local\n * development due to security policies. If the `useSingleWebServer` feature is enabled, the app\n * server will also serve bundles rather than creating a separate bundle server.\n */\nexport async function startServers(\n options: {\n definition: PackageJson;\n /** If provided, act as a middleware on this server, rather than starting a new server. */\n expressServer?: Server;\n /** Custom port for the app server (probably from CLI options) */\n port?: number | number[];\n bundleServerOptions: BundleServerOptions;\n },\n context: PartialContext<'reporter', 'config' | 'projectName'> & BundleServerContext,\n): Promise<{\n appServer: AppServer;\n bundleServer?: BundleServer;\n}> {\n const { definition, expressServer, bundleServerOptions } = options;\n const { session, reporter } = context;\n const { config } = session;\n const { server = {} } = config;\n\n // Read the port from the config file or default to array of ports.\n const customPorts = server.port ?? options.port;\n const ports = customPorts ?? [5000, 5001, 5002, 5003];\n const task = reporter.addTask(`Starting app server for \"${definition.name}\"`);\n const hostname = getDomain(server.domain);\n\n try {\n const { app, close, port, url } = await createExpressApp({\n portRange: ports,\n requireSpecifiedPort: customPorts !== undefined,\n hostname,\n requestHeaders: server?.requestHeaders,\n sslOptions: server?.https,\n server: expressServer,\n cwd: config.appPath,\n });\n session.urls.appServer = url;\n\n let bundleServer: BundleServer | undefined;\n if (config.features?.useSingleWebServer) {\n // Add a route on this server for bundles.\n session.urls.bundleServer = `${url}/${combinedServerBundleRequestPrefix}`;\n app.get(`/${combinedServerBundleRequestPrefix}/*`, (req, res) => {\n handleBundleRequest({ req, res, ...bundleServerOptions }, context).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error bundling: ${err}`);\n });\n });\n } else {\n // Start the bundle server.\n bundleServer = await startBundleServer(bundleServerOptions, context);\n }\n\n createRoutes({ ...options, app, url }, context);\n\n task.complete({ message: `Available @ ${cyan(url)}`, forceShow: true });\n\n return {\n appServer: { app, close, port, url },\n bundleServer,\n };\n } catch (err: unknown) {\n task.complete({ status: 'fail', message: 'Failed to start app server', forceShow: true });\n handleErrorPortUnavailable(err, session.projectName, ports);\n\n throw err;\n }\n}\n"]}
1
+ {"version":3,"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GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE;YACpC,YAAY;SACb,CAAC;IACJ,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,4BAA4B,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1F,0BAA0B,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAE5D,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["import type { Context } from '@ms-cloudpack/api-server';\nimport {\n handleBundleRequest,\n startBundleServer,\n type BundleServer,\n type BundleServerOptions,\n} from '@ms-cloudpack/bundle-server';\nimport type { PackageJson } from '@ms-cloudpack/common-types';\nimport { createExpressApp, getDomain } from '@ms-cloudpack/create-express-app';\nimport { combinedServerBundleRequestPrefix } from '@ms-cloudpack/import-map';\nimport { cyan } from '@ms-cloudpack/task-reporter';\nimport type { Server } from 'http';\nimport { createRoutes } from './createRoutes.js';\nimport { handleErrorPortUnavailable } from './handleErrorPortUnavailable.js';\nimport type { AppServer } from './types/AppServer.js';\n\n/**\n * Start the app server, and (usually) the bundle server (but see below).\n *\n * The app server hosts the appropriate routes for the web app, primarily returning html content\n * which loads resources from the bundle server.\n *\n * Separating the app server from the bundle service keeps the routes separate - the app server\n * can support whichever routes the app needs, while the bundle server can provide package\n * assets in various forms using its own routing.\n *\n * Exception: some projects need the bundle server and app server on the same origin for local\n * development due to security policies. If the `useSingleWebServer` feature is enabled, the app\n * server will also serve bundles rather than creating a separate bundle server.\n */\nexport async function startServers(\n options: {\n definition: PackageJson;\n /** If provided, act as a middleware on this server, rather than starting a new server. */\n expressServer?: Server;\n /** Custom port for the app server (probably from CLI options) */\n port?: number | number[];\n bundleServerOptions: BundleServerOptions;\n },\n context: Context,\n): Promise<{\n appServer: AppServer;\n bundleServer?: BundleServer;\n}> {\n const { definition, expressServer, bundleServerOptions } = options;\n const { session, reporter } = context;\n const { config } = session;\n const { server = {} } = config;\n\n // Read the port from the config file or default to array of ports.\n const customPorts = server.port ?? options.port;\n const ports = customPorts ?? [5000, 5001, 5002, 5003];\n const task = reporter.addTask(`Starting app server for \"${definition.name}\"`);\n const hostname = getDomain(server.domain);\n\n try {\n const { app, close, port, url } = await createExpressApp({\n portRange: ports,\n requireSpecifiedPort: customPorts !== undefined,\n hostname,\n requestHeaders: server?.requestHeaders,\n sslOptions: server?.https,\n server: expressServer,\n cwd: config.appPath,\n });\n session.urls.appServer = url;\n\n let bundleServer: BundleServer | undefined;\n if (config.features?.useSingleWebServer) {\n // Add a route on this server for bundles.\n session.urls.bundleServer = `${url}/${combinedServerBundleRequestPrefix}`;\n app.get(`/${combinedServerBundleRequestPrefix}/*`, (req, res) => {\n handleBundleRequest({ req, res, ...bundleServerOptions }, context).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error bundling: ${err}`);\n });\n });\n } else {\n // Start the bundle server.\n bundleServer = await startBundleServer(bundleServerOptions, context);\n }\n\n createRoutes({ ...options, app, url }, context);\n\n task.complete({ message: `Available @ ${cyan(url)}`, forceShow: true });\n\n return {\n appServer: { app, close, port, url },\n bundleServer,\n };\n } catch (err: unknown) {\n task.complete({ status: 'fail', message: 'Failed to start app server', forceShow: true });\n handleErrorPortUnavailable(err, session.projectName, ports);\n\n throw err;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/app-server",
3
- "version": "0.17.50",
3
+ "version": "0.17.52",
4
4
  "description": "An implementation of the App server for Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,12 +14,12 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/api-server": "^0.60.1",
18
- "@ms-cloudpack/bundle-server": "^0.6.59",
17
+ "@ms-cloudpack/api-server": "^0.61.0",
18
+ "@ms-cloudpack/bundle-server": "^0.6.61",
19
19
  "@ms-cloudpack/common-types": "^0.24.7",
20
20
  "@ms-cloudpack/create-express-app": "^1.10.19",
21
- "@ms-cloudpack/import-map": "^0.8.31",
22
- "@ms-cloudpack/overlay": "^0.17.131",
21
+ "@ms-cloudpack/import-map": "^0.9.0",
22
+ "@ms-cloudpack/overlay": "^0.17.133",
23
23
  "@ms-cloudpack/path-string-parsing": "^1.2.6",
24
24
  "@ms-cloudpack/path-utilities": "^3.0.4",
25
25
  "@ms-cloudpack/task-reporter": "^0.15.1",