@ms-cloudpack/app-server 0.20.5 → 0.20.6

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.
Files changed (44) hide show
  1. package/lib/createRoutes.d.ts.map +1 -1
  2. package/lib/createRoutes.js +5 -2
  3. package/lib/createRoutes.js.map +1 -1
  4. package/lib/renderRoute/getCustomRenderErrorHandler.d.ts +37 -0
  5. package/lib/renderRoute/getCustomRenderErrorHandler.d.ts.map +1 -0
  6. package/lib/renderRoute/getCustomRenderErrorHandler.js +51 -0
  7. package/lib/renderRoute/getCustomRenderErrorHandler.js.map +1 -0
  8. package/lib/renderRoute/renderRoute.js +30 -45
  9. package/lib/renderRoute/renderRoute.js.map +1 -1
  10. package/lib/renderRoute/ssr/bundleServerEntry.d.ts +8 -2
  11. package/lib/renderRoute/ssr/bundleServerEntry.d.ts.map +1 -1
  12. package/lib/renderRoute/ssr/bundleServerEntry.js +28 -21
  13. package/lib/renderRoute/ssr/bundleServerEntry.js.map +1 -1
  14. package/lib/renderRoute/ssr/renderCustomScript.d.ts +2 -0
  15. package/lib/renderRoute/ssr/renderCustomScript.d.ts.map +1 -1
  16. package/lib/renderRoute/ssr/renderCustomScript.js +15 -69
  17. package/lib/renderRoute/ssr/renderCustomScript.js.map +1 -1
  18. package/lib/renderRoute/ssr/runServerEntryInWorker.d.ts +5 -4
  19. package/lib/renderRoute/ssr/runServerEntryInWorker.d.ts.map +1 -1
  20. package/lib/renderRoute/ssr/runServerEntryInWorker.js +17 -6
  21. package/lib/renderRoute/ssr/runServerEntryInWorker.js.map +1 -1
  22. package/lib/renderRoute/ssr/types/RunScriptResult.d.ts +12 -0
  23. package/lib/renderRoute/ssr/types/RunScriptResult.d.ts.map +1 -0
  24. package/lib/renderRoute/ssr/types/RunScriptResult.js +2 -0
  25. package/lib/renderRoute/ssr/types/RunScriptResult.js.map +1 -0
  26. package/lib/renderRoute/ssr/types/RunServerEntryOptions.d.ts +2 -2
  27. package/lib/renderRoute/ssr/types/RunServerEntryOptions.d.ts.map +1 -1
  28. package/lib/renderRoute/ssr/types/RunServerEntryOptions.js.map +1 -1
  29. package/lib/renderRoute/ssr/worker/importAndRunScript.d.ts +16 -0
  30. package/lib/renderRoute/ssr/worker/importAndRunScript.d.ts.map +1 -0
  31. package/lib/renderRoute/ssr/worker/importAndRunScript.js +70 -0
  32. package/lib/renderRoute/ssr/worker/importAndRunScript.js.map +1 -0
  33. package/lib/renderRoute/ssr/worker/runServerEntry.d.ts +7 -4
  34. package/lib/renderRoute/ssr/worker/runServerEntry.d.ts.map +1 -1
  35. package/lib/renderRoute/ssr/worker/runServerEntry.js +68 -30
  36. package/lib/renderRoute/ssr/worker/runServerEntry.js.map +1 -1
  37. package/lib/startServers.d.ts.map +1 -1
  38. package/lib/startServers.js +1 -0
  39. package/lib/startServers.js.map +1 -1
  40. package/package.json +9 -9
  41. package/lib/renderRoute/getErrorResponse.d.ts +0 -21
  42. package/lib/renderRoute/getErrorResponse.d.ts.map +0 -1
  43. package/lib/renderRoute/getErrorResponse.js +0 -44
  44. package/lib/renderRoute/getErrorResponse.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"startServers.d.ts","sourceRoot":"","sources":["../src/startServers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAI9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE;IACP,UAAU,EAAE,WAAW,CAAC;IACxB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,EACD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC;IACT,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC,CA4DD"}
1
+ {"version":3,"file":"startServers.d.ts","sourceRoot":"","sources":["../src/startServers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAI9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE;IACP,UAAU,EAAE,WAAW,CAAC;IACxB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,EACD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC;IACT,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC,CA6DD"}
@@ -43,6 +43,7 @@ export async function startServers(options, context) {
43
43
  let bundleServer;
44
44
  if (config.features?.useSingleWebServer) {
45
45
  // Add a route on this server for bundles.
46
+ // It must be the first route defined so it takes precedence over any user-provided * routes.
46
47
  session.urls.bundleServer = `${url}/${combinedServerBundleRequestPrefix}`;
47
48
  app.get(`/${combinedServerBundleRequestPrefix}/*`, (req, res) => {
48
49
  handleBundleRequest({ req, res, ...bundleServerOptions }, context).catch((err) => {
@@ -1 +1 @@
1
- {"version":3,"file":"startServers.js","sourceRoot":"","sources":["../src/startServers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAGlB,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,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAE3F;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAOC,EACD,OAAgB;IAKhB,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IACnE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAE/B,mEAAmE;IACnE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAChD,MAAM,KAAK,GAAG,WAAW,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,4BAA4B,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE1C,IAAI,CAAC;QACH,MA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AG,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;gBACT,GAAG;gBACH,IAAI;gBACJ,GAAG;gBACH,KAAK,EAAE,KAAK,IAAI,EAAE;oBAChB,MAAM,KAAK,EAAE,CAAC;oBACd,MAAM,4BAA4B,EAAE,CAAC;gBACvC,CAAC;aACF;YACD,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,uBAAuB,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACjD,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 { handleKnownServerErrors } from './handleKnownServerErrors.js';\nimport type { AppServer } from './types/AppServer.js';\nimport { disposeServerEntryWorkerPool } from './renderRoute/ssr/runServerEntryInWorker.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: context.session.config?.server?.parsedHttps ?? context.session.config?.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: {\n app,\n port,\n url,\n close: async () => {\n await close();\n await disposeServerEntryWorkerPool();\n },\n },\n bundleServer,\n };\n } catch (err: unknown) {\n task.complete({ status: 'fail', message: 'Failed to start app server', forceShow: true });\n handleKnownServerErrors({ err, ports }, context);\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,GAGlB,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,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAE3F;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAOC,EACD,OAAgB;IAKhB,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IACnE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAE/B,mEAAmE;IACnE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAChD,MAAM,KAAK,GAAG,WAAW,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,4BAA4B,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,M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AE,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;gBACT,GAAG;gBACH,IAAI;gBACJ,GAAG;gBACH,KAAK,EAAE,KAAK,IAAI,EAAE;oBAChB,MAAM,KAAK,EAAE,CAAC;oBACd,MAAM,4BAA4B,EAAE,CAAC;gBACvC,CAAC;aACF;YACD,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,uBAAuB,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACjD,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 { handleKnownServerErrors } from './handleKnownServerErrors.js';\nimport type { AppServer } from './types/AppServer.js';\nimport { disposeServerEntryWorkerPool } from './renderRoute/ssr/runServerEntryInWorker.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: context.session.config?.server?.parsedHttps ?? context.session.config?.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 // It must be the first route defined so it takes precedence over any user-provided * routes.\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: {\n app,\n port,\n url,\n close: async () => {\n await close();\n await disposeServerEntryWorkerPool();\n },\n },\n bundleServer,\n };\n } catch (err: unknown) {\n task.complete({ status: 'fail', message: 'Failed to start app server', forceShow: true });\n handleKnownServerErrors({ err, ports }, context);\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.20.5",
3
+ "version": "0.20.6",
4
4
  "description": "An implementation of the App server for Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,15 +14,15 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/api-server": "^0.64.13",
18
- "@ms-cloudpack/bundle-server": "^0.8.5",
19
- "@ms-cloudpack/common-types": "^0.27.0",
20
- "@ms-cloudpack/create-express-app": "^1.10.44",
17
+ "@ms-cloudpack/api-server": "^0.64.14",
18
+ "@ms-cloudpack/bundle-server": "^0.8.6",
19
+ "@ms-cloudpack/common-types": "^0.27.1",
20
+ "@ms-cloudpack/create-express-app": "^1.10.45",
21
21
  "@ms-cloudpack/environment": "^0.1.1",
22
- "@ms-cloudpack/import-map": "^0.10.38",
23
- "@ms-cloudpack/inline-scripts": "^0.2.27",
22
+ "@ms-cloudpack/import-map": "^0.10.39",
23
+ "@ms-cloudpack/inline-scripts": "^0.2.28",
24
24
  "@ms-cloudpack/path-string-parsing": "^1.2.7",
25
- "@ms-cloudpack/path-utilities": "^3.1.15",
25
+ "@ms-cloudpack/path-utilities": "^3.1.16",
26
26
  "@ms-cloudpack/task-reporter": "^0.17.2",
27
27
  "@ms-cloudpack/worker-pool": "^0.4.1",
28
28
  "happy-dom": "^18.0.0",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@ms-cloudpack/common-types-browser": "^0.6.2",
33
- "@ms-cloudpack/config": "^0.37.3",
33
+ "@ms-cloudpack/config": "^0.37.4",
34
34
  "@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
35
35
  "@ms-cloudpack/scripts": "^0.0.1",
36
36
  "@ms-cloudpack/test-utilities": "^0.5.0"
@@ -1,21 +0,0 @@
1
- import type { ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';
2
- import type { RenderRouteOptions } from '../types/RenderRouteOptions.js';
3
- /**
4
- * Log the error to the console and return an error response (500 status code).
5
- *
6
- * If it appears that the given request accepts HTML, it returns an HTML page,
7
- * or plain text otherwise.
8
- */
9
- export declare function getErrorResponse(params: Pick<RenderRouteOptions, 'req'> & {
10
- message: string;
11
- }): ExpandedRenderFunctionResult;
12
- /**
13
- * Fill in details of the message, log to console.error, and return an error response.
14
- * `Route ${route.match} with (renderScript|serverEntry) "${scriptPath}" ${message}`
15
- */
16
- export declare function getCustomRenderErrorResponse(params: Pick<RenderRouteOptions, 'req' | 'route'> & {
17
- /** Error details (NOTE the format in the main function comment) */
18
- message: string;
19
- scriptPath: string | undefined;
20
- }): ExpandedRenderFunctionResult;
21
- //# sourceMappingURL=getErrorResponse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getErrorResponse.d.ts","sourceRoot":"","sources":["../../src/renderRoute/getErrorResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,GAAG;IACxC,OAAO,EAAE,MAAM,CAAC;CACjB,GACA,4BAA4B,CA0B9B;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG;IAClD,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,GACA,4BAA4B,CAO9B"}
@@ -1,44 +0,0 @@
1
- import { isHtmlAcceptable } from './isHtmlAcceptable.js';
2
- const statusCode = 500;
3
- /**
4
- * Log the error to the console and return an error response (500 status code).
5
- *
6
- * If it appears that the given request accepts HTML, it returns an HTML page,
7
- * or plain text otherwise.
8
- */
9
- export function getErrorResponse(params) {
10
- const { message, req } = params;
11
- console.error(`App server: request ${req.url} - ${message}`);
12
- if (!isHtmlAcceptable(req)) {
13
- // If HTML is not acceptable, return a plain text response
14
- return {
15
- content: message,
16
- statusCode,
17
- contentType: 'text/plain',
18
- };
19
- }
20
- return {
21
- content: `<!DOCTYPE html>
22
- <html lang="en">
23
- <head><title>Error</title></head>
24
- <body>
25
- <h1>Error</h1>
26
- <pre>${message}</pre>
27
- </body>
28
- </html>`,
29
- statusCode,
30
- contentType: 'text/html',
31
- };
32
- }
33
- /**
34
- * Fill in details of the message, log to console.error, and return an error response.
35
- * `Route ${route.match} with (renderScript|serverEntry) "${scriptPath}" ${message}`
36
- */
37
- export function getCustomRenderErrorResponse(params) {
38
- const { message, req, route, scriptPath } = params;
39
- const scriptType = route.serverEntry ? 'serverEntry' : 'renderScript';
40
- const renderer = scriptPath ? `${scriptType} "${scriptPath}"` : 'the default renderer';
41
- const content = `Route ${JSON.stringify(route.match)} with ${renderer} ${message}`;
42
- return getErrorResponse({ req, message: content });
43
- }
44
- //# sourceMappingURL=getErrorResponse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getErrorResponse.js","sourceRoot":"","sources":["../../src/renderRoute/getErrorResponse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAEC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAEhC,OAAO,CAAC,KAAK,CAAC,uBAAuB,GAAG,CAAC,GAAG,MAAM,OAAO,EAAE,CAAC,CAAC;IAE7D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,0DAA0D;QAC1D,OAAO;YACL,OAAO,EAAE,OAAO;YAChB,UAAU;YACV,WAAW,EAAE,YAAY;SAC1B,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE;;;;;SAKJ,OAAO;;QAER;QACJ,UAAU;QACV,WAAW,EAAE,WAAW;KACzB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAC1C,MAIC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACnD,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC;IACtE,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,KAAK,UAAU,GAAG,CAAC,CAAC,CAAC,sBAAsB,CAAC;IACvF,MAAM,OAAO,GAAG,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,QAAQ,IAAI,OAAO,EAAE,CAAC;IAEnF,OAAO,gBAAgB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import type { ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';\nimport { isHtmlAcceptable } from './isHtmlAcceptable.js';\nimport type { RenderRouteOptions } from '../types/RenderRouteOptions.js';\n\nconst statusCode = 500;\n\n/**\n * Log the error to the console and return an error response (500 status code).\n *\n * If it appears that the given request accepts HTML, it returns an HTML page,\n * or plain text otherwise.\n */\nexport function getErrorResponse(\n params: Pick<RenderRouteOptions, 'req'> & {\n message: string;\n },\n): ExpandedRenderFunctionResult {\n const { message, req } = params;\n\n console.error(`App server: request ${req.url} - ${message}`);\n\n if (!isHtmlAcceptable(req)) {\n // If HTML is not acceptable, return a plain text response\n return {\n content: message,\n statusCode,\n contentType: 'text/plain',\n };\n }\n\n return {\n content: `<!DOCTYPE html>\n<html lang=\"en\">\n<head><title>Error</title></head>\n<body>\n <h1>Error</h1>\n <pre>${message}</pre>\n</body>\n</html>`,\n statusCode,\n contentType: 'text/html',\n };\n}\n\n/**\n * Fill in details of the message, log to console.error, and return an error response.\n * `Route ${route.match} with (renderScript|serverEntry) \"${scriptPath}\" ${message}`\n */\nexport function getCustomRenderErrorResponse(\n params: Pick<RenderRouteOptions, 'req' | 'route'> & {\n /** Error details (NOTE the format in the main function comment) */\n message: string;\n scriptPath: string | undefined;\n },\n): ExpandedRenderFunctionResult {\n const { message, req, route, scriptPath } = params;\n const scriptType = route.serverEntry ? 'serverEntry' : 'renderScript';\n const renderer = scriptPath ? `${scriptType} \"${scriptPath}\"` : 'the default renderer';\n const content = `Route ${JSON.stringify(route.match)} with ${renderer} ${message}`;\n\n return getErrorResponse({ req, message: content });\n}\n"]}