@ms-cloudpack/app-server 0.14.4 → 0.15.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.
@@ -1,5 +1,5 @@
1
1
  import { handleBundleRequest, startBundleServer, } from '@ms-cloudpack/bundle-server';
2
- import { createExpressApp } from '@ms-cloudpack/create-express-app';
2
+ import { createExpressApp, getDomain } from '@ms-cloudpack/create-express-app';
3
3
  import { combinedServerBundleRequestPrefix } from '@ms-cloudpack/import-map';
4
4
  import { cyan } from '@ms-cloudpack/task-reporter';
5
5
  import { createRoutes } from './createRoutes.js';
@@ -27,11 +27,12 @@ export async function startServers(options, context) {
27
27
  const requireSpecifiedPort = devServer.port !== undefined;
28
28
  const ports = devServer.port ?? [5000, 5001, 5002, 5003];
29
29
  const task = reporter.addTask(`Starting app server for "${definition.name}"`);
30
+ const hostname = getDomain(devServer.domain);
30
31
  try {
31
32
  const { app, close, port, url } = await createExpressApp({
32
33
  portRange: ports,
33
34
  requireSpecifiedPort,
34
- hostname: devServer?.domain,
35
+ hostname,
35
36
  requestHeaders: devServer?.requestHeaders,
36
37
  sslOptions: devServer?.https,
37
38
  server,
@@ -1 +1 @@
1
- {"version":3,"file":"startServers.js","sourceRoot":"","sources":["../src/startServers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAIlB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAG7E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAKC,EACD,OAAmF;IAKnF,M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G,mBAAmB,EAAE,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBAC/E,OAAO,CAAC,KAAK,CAAE,GAAa,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;oBAC5C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;gBACjD,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,2BAA2B;YAC3B,YAAY,GAAG,MAAM,iBAAiB,CAAC,mBAAmB,EAAE,OAAO,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 } 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 server?: Server;\n bundleServerOptions: BundleServerOptions;\n },\n context: PartialContext<'reporter', 'config' | 'projectName'> & BundleServerContext,\n): Promise<{\n appServer: AppServer;\n bundleServer?: BundleServer;\n}> {\n const { definition, server, bundleServerOptions } = options;\n const { session, reporter } = context;\n const { config } = session;\n const { devServer = {} } = config;\n\n // Read the port from the config file or default to array of ports.\n const requireSpecifiedPort = devServer.port !== undefined;\n const ports = devServer.port ?? [5000, 5001, 5002, 5003];\n\n const task = reporter.addTask(`Starting app server for \"${definition.name}\"`);\n\n try {\n const { app, close, port, url } = await createExpressApp({\n portRange: ports,\n requireSpecifiedPort,\n hostname: devServer?.domain,\n requestHeaders: devServer?.requestHeaders,\n sslOptions: devServer?.https,\n server,\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,"file":"startServers.js","sourceRoot":"","sources":["../src/startServers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAIlB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAG7E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAKC,EACD,OAAmF;IAKnF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IAC5D,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAElC,mEAAmE;IACnE,MAAM,oBAAoB,GAAG,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC;IAC1D,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI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BAAmB,EAAE,OAAO,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 server?: Server;\n bundleServerOptions: BundleServerOptions;\n },\n context: PartialContext<'reporter', 'config' | 'projectName'> & BundleServerContext,\n): Promise<{\n appServer: AppServer;\n bundleServer?: BundleServer;\n}> {\n const { definition, server, bundleServerOptions } = options;\n const { session, reporter } = context;\n const { config } = session;\n const { devServer = {} } = config;\n\n // Read the port from the config file or default to array of ports.\n const requireSpecifiedPort = devServer.port !== undefined;\n const ports = devServer.port ?? [5000, 5001, 5002, 5003];\n const task = reporter.addTask(`Starting app server for \"${definition.name}\"`);\n const hostname = getDomain(devServer.domain);\n\n try {\n const { app, close, port, url } = await createExpressApp({\n portRange: ports,\n requireSpecifiedPort,\n hostname,\n requestHeaders: devServer?.requestHeaders,\n sslOptions: devServer?.https,\n server,\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.14.4",
3
+ "version": "0.15.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.48.9",
18
- "@ms-cloudpack/bundle-server": "^0.4.53",
19
- "@ms-cloudpack/common-types": "^0.16.1",
20
- "@ms-cloudpack/create-express-app": "^1.7.5",
21
- "@ms-cloudpack/import-map": "^0.6.4",
22
- "@ms-cloudpack/overlay": "^0.17.52",
17
+ "@ms-cloudpack/api-server": "^0.49.0",
18
+ "@ms-cloudpack/bundle-server": "^0.5.0",
19
+ "@ms-cloudpack/common-types": "^0.17.0",
20
+ "@ms-cloudpack/create-express-app": "^1.8.0",
21
+ "@ms-cloudpack/import-map": "^0.6.5",
22
+ "@ms-cloudpack/overlay": "^0.17.53",
23
23
  "@ms-cloudpack/path-string-parsing": "^1.2.4",
24
- "@ms-cloudpack/path-utilities": "^2.7.34",
24
+ "@ms-cloudpack/path-utilities": "^2.7.35",
25
25
  "@ms-cloudpack/task-reporter": "^0.14.4",
26
26
  "jsdom": "^24.0.0"
27
27
  },