@ms-cloudpack/app-server 0.2.13 → 0.3.1

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,8 +1,7 @@
1
- import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
1
+ import type { CloudpackConfig, PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';
2
2
  import type { Express } from '@ms-cloudpack/create-express-app';
3
3
  import type { BundleServer } from '@ms-cloudpack/bundle-server';
4
4
  import type { ApiServer, Session } from '@ms-cloudpack/api-server';
5
- import type { CloudpackConfig, PackageJson } from '@ms-cloudpack/config-types';
6
5
  import type { PackageImportPaths } from '@ms-cloudpack/import-map';
7
6
  import type { PackageHashes } from '@ms-cloudpack/package-hashes';
8
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,kCAAkC,CAAC;AAKnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAInE,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,aAAa,GACd,EAAE;IACD,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,MAAM,C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UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;oBACtD,MAAM,aAAa,GAAG,MAAM,gBAAgB,EAAE,CAAC;oBAC/C,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,eAAe,CAAC;wBACjE,KAAK;wBACL,OAAO,EAAE,GAAG;wBACZ,SAAS;wBACT,aAAa;wBACb,WAAW;wBACX,OAAO;wBACP,UAAU;wBACV,aAAa;wBACb,GAAG;wBACH,GAAG;qBACJ,CAAC,CAAC;oBAEH,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;oBAE7D,OAAO,CAAC,KAAK,CAAC,wBAAwB,WAAW,UAAU,UAAU,EAAE,CAAC,CAAC;gBAC3E,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACjB,OAAO,CAAC,KAAK,CAAE,GAAa,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;oBAC5C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;gBACpD,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-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 type { BundleServer } from '@ms-cloudpack/bundle-server';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport { getHtmlResponse } from './getHtmlResponse.js';\nimport { getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { setHeaders } from './setHeaders.js';\nimport type { CloudpackConfig, PackageJson } from '@ms-cloudpack/config-types';\nimport type { PackageImportPaths } from '@ms-cloudpack/import-map';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\n\n/**\n * Creates the routes for the express app, considering how the config is defined.\n */\nexport function createRoutes({\n app,\n url,\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n packages,\n packageImportPaths,\n packageHashes,\n}: {\n app: Express;\n url: string;\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\n packageImportPaths: PackageImportPaths;\n packageHashes: PackageHashes;\n}) {\n const routes = [...(config.devServer?.routes || [])];\n const hasDefaultRoute = routes.some((route) => route.match === '*' || route.match === '/');\n\n if (!hasDefaultRoute) {\n routes.push({\n match: '*',\n exportEntry: '.',\n });\n }\n\n // Hashes from external packages to be used in the import map.\n const getPackageHash = (packagePath: string) => {\n return packageHashes.get({ packagePath, isSourceHashingEnabled: false });\n };\n\n for (const route of routes) {\n if (route.staticPath) {\n app.use(route.match, express.static(path.resolve(session.appPath, route.staticPath)));\n } else {\n app.get(route.match, (req: Request, res: Response) => {\n (async () => {\n // Build the import map if it hasn't been built yet for this session version.\n const importMap =\n session.getImportMap() ||\n session.setImportMap(\n await createImportMap(\n {\n resolveMap: session.resolveMap,\n bundleServerUrl: bundleServer.url,\n sessionVersion: session.getSessionVersion(),\n targetVersions: session.targetVersions,\n },\n { packages, packageImportPaths, getPackageHash, config: session.config },\n ),\n );\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 const entryScript =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n route.exportEntry && importMap.imports[slash(path.join(definition.name!, route.exportEntry))];\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, apiServer, bundleServer });\n const inlineScripts = await getInlineScripts();\n const { content, statusCode, contentType } = await getHtmlResponse({\n route,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n session,\n definition,\n inlineScripts,\n req,\n res,\n });\n\n res.type(contentType).status(statusCode).send(content).end();\n\n console.debug(`App server: Request: ${requestPath}, ext: ${requestExt}`);\n })().catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error loading app: ${err}`);\n });\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AAEA,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;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7C;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,GAAG,EACH,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,aAAa,GAYd;IACC,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;IACrD,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,KAAK,GAA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AC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJson } 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 type { BundleServer } from '@ms-cloudpack/bundle-server';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport { getHtmlResponse } from './getHtmlResponse.js';\nimport { getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { setHeaders } from './setHeaders.js';\nimport type { PackageImportPaths } from '@ms-cloudpack/import-map';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\n\n/**\n * Creates the routes for the express app, considering how the config is defined.\n */\nexport function createRoutes({\n app,\n url,\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n packages,\n packageImportPaths,\n packageHashes,\n}: {\n app: Express;\n url: string;\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\n packageImportPaths: PackageImportPaths;\n packageHashes: PackageHashes;\n}) {\n const routes = [...(config.devServer?.routes || [])];\n const hasDefaultRoute = routes.some((route) => route.match === '*' || route.match === '/');\n\n if (!hasDefaultRoute) {\n routes.push({\n match: '*',\n exportEntry: '.',\n });\n }\n\n // Hashes from external packages to be used in the import map.\n const getPackageHash = (packagePath: string) => {\n return packageHashes.get({ packagePath, isSourceHashingEnabled: false });\n };\n\n for (const route of routes) {\n if (route.staticPath) {\n app.use(route.match, express.static(path.resolve(session.appPath, route.staticPath)));\n } else {\n app.get(route.match, (req: Request, res: Response) => {\n (async () => {\n // Build the import map if it hasn't been built yet for this session version.\n const importMap =\n session.getImportMap() ||\n session.setImportMap(\n await createImportMap(\n {\n resolveMap: session.resolveMap,\n bundleServerUrl: bundleServer.url,\n sessionVersion: session.getSessionVersion(),\n targetVersions: session.targetVersions,\n },\n { packages, packageImportPaths, getPackageHash, config: session.config },\n ),\n );\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 const entryScript =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n route.exportEntry && importMap.imports[slash(path.join(definition.name!, route.exportEntry))];\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, apiServer, bundleServer });\n const inlineScripts = await getInlineScripts();\n const { content, statusCode, contentType } = await getHtmlResponse({\n route,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n session,\n definition,\n inlineScripts,\n req,\n res,\n });\n\n res.type(contentType).status(statusCode).send(content).end();\n\n console.debug(`App server: Request: ${requestPath}, ext: ${requestExt}`);\n })().catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error loading app: ${err}`);\n });\n });\n }\n }\n}\n"]}
@@ -1,8 +1,7 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import type { BundleServer } from '@ms-cloudpack/bundle-server';
3
- import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
3
+ import type { CloudpackConfig, PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';
4
4
  import { type TaskReporter } from '@ms-cloudpack/task-reporter';
5
- import type { CloudpackConfig, PackageJson } from '@ms-cloudpack/config-types';
6
5
  import type { ApiServer, Session } from '@ms-cloudpack/api-server';
7
6
  import type { PackageImportPaths } from '@ms-cloudpack/import-map';
8
7
  import type { PackageHashes } from '@ms-cloudpack/package-hashes';
@@ -1 +1 @@
1
- {"version":3,"file":"startAppServer.d.ts","sourceRoot":"","sources":["../src/startAppServer.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAG3E,OAAO,EAAE,KAAK,YAAY,EAAQ,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,YAAY,EACZ,SAAS,EACT,UAAU,EACV,MAA8B,EAC9B,QAAQ,EACR,kBAAkB,EAClB,QAAQ,EACR,aAAa,EACb,cAAc,EACd,MAAM,GACP,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,WAAW,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,QAAQ,EAAE,YAAY,CAAC;IACvB,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,SAAS,CAAC,CAoDrB"}
1
+ {"version":3,"file":"startAppServer.d.ts","sourceRoot":"","sources":["../src/startAppServer.ts"],"names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AAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,eAAe,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAExE,OAAO;YACL,GAAG;YACH,KAAK;YACL,IAAI;YACJ,GAAG;SACJ,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 { createExpressApp } from '@ms-cloudpack/create-express-app';\nimport type { BundleServer } from '@ms-cloudpack/bundle-server';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { createRoutes } from './createRoutes.js';\nimport { handleErrorPortUnavailable } from './handleErrorPortUnavailable.js';\nimport { type TaskReporter, cyan } from '@ms-cloudpack/task-reporter';\nimport type { CloudpackConfig, PackageJson } from '@ms-cloudpack/config-types';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport type { PackageImportPaths } from '@ms-cloudpack/import-map';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\nimport type { Server } from 'http';\nimport type { AppServer } from './types/AppServer.js';\n\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 */\nexport async function startAppServer({\n session,\n bundleServer,\n apiServer,\n definition,\n config = {} as CloudpackConfig,\n packages,\n packageImportPaths,\n reporter,\n packageHashes,\n middlewareMode,\n server,\n}: {\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\n packageImportPaths: PackageImportPaths;\n reporter: TaskReporter;\n packageHashes: PackageHashes;\n middlewareMode?: boolean;\n server?: Server;\n}): Promise<AppServer> {\n const { devServer = {} } = config || ({} as CloudpackConfig);\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 // Directory to serve as plain static assets. Defaults to \"public\".\n // Can be overridden by setting the 'publicDir' option in the cloudpack config.\n // const publicDir = path.resolve(devServer.publicPath ?? 'public');\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: config.devServer?.https,\n // publicDir,\n middlewareMode,\n server,\n });\n\n createRoutes({\n app,\n url,\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n packages,\n packageImportPaths,\n packageHashes,\n });\n\n task.complete({ message: `Available @ ${cyan(url)}`, forceShow: true });\n\n return {\n app,\n close,\n port,\n url,\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":"startAppServer.js","sourceRoot":"","sources":["../src/startAppServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAqB,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAOtE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,YAAY,EACZ,SAAS,EACT,UAAU,EACV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Q,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 { createExpressApp } from '@ms-cloudpack/create-express-app';\nimport type { BundleServer } from '@ms-cloudpack/bundle-server';\nimport type { CloudpackConfig, PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';\nimport { createRoutes } from './createRoutes.js';\nimport { handleErrorPortUnavailable } from './handleErrorPortUnavailable.js';\nimport { type TaskReporter, cyan } from '@ms-cloudpack/task-reporter';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport type { PackageImportPaths } from '@ms-cloudpack/import-map';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\nimport type { Server } from 'http';\nimport type { AppServer } from './types/AppServer.js';\n\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 */\nexport async function startAppServer({\n session,\n bundleServer,\n apiServer,\n definition,\n config = {} as CloudpackConfig,\n packages,\n packageImportPaths,\n reporter,\n packageHashes,\n middlewareMode,\n server,\n}: {\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\n packageImportPaths: PackageImportPaths;\n reporter: TaskReporter;\n packageHashes: PackageHashes;\n middlewareMode?: boolean;\n server?: Server;\n}): Promise<AppServer> {\n const { devServer = {} } = config || ({} as CloudpackConfig);\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 // Directory to serve as plain static assets. Defaults to \"public\".\n // Can be overridden by setting the 'publicDir' option in the cloudpack config.\n // const publicDir = path.resolve(devServer.publicPath ?? 'public');\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: config.devServer?.https,\n // publicDir,\n middlewareMode,\n server,\n });\n\n createRoutes({\n app,\n url,\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n packages,\n packageImportPaths,\n packageHashes,\n });\n\n task.complete({ message: `Available @ ${cyan(url)}`, forceShow: true });\n\n return {\n app,\n close,\n port,\n url,\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.2.13",
3
+ "version": "0.3.1",
4
4
  "description": "An implementation of the App server for Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,14 +14,13 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/api-server": "^0.33.5",
18
- "@ms-cloudpack/bundle-server": "^0.2.43",
19
- "@ms-cloudpack/bundler-types": "^0.25.2",
20
- "@ms-cloudpack/config-types": "^0.7.0",
21
- "@ms-cloudpack/create-express-app": "^1.5.2",
22
- "@ms-cloudpack/import-map": "^0.1.5",
23
- "@ms-cloudpack/overlay": "^0.16.92",
24
- "@ms-cloudpack/package-hashes": "^0.4.0",
17
+ "@ms-cloudpack/api-server": "^0.34.1",
18
+ "@ms-cloudpack/bundle-server": "^0.2.45",
19
+ "@ms-cloudpack/common-types": "^0.1.1",
20
+ "@ms-cloudpack/create-express-app": "^1.6.0",
21
+ "@ms-cloudpack/import-map": "^0.2.0",
22
+ "@ms-cloudpack/overlay": "^0.16.94",
23
+ "@ms-cloudpack/package-hashes": "^0.5.0",
25
24
  "@ms-cloudpack/path-string-parsing": "^1.2.1",
26
25
  "@ms-cloudpack/path-utilities": "^2.6.1",
27
26
  "@ms-cloudpack/task-reporter": "^0.11.3",