@ms-cloudpack/create-express-app 1.3.16 → 1.4.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.
@@ -9,8 +9,11 @@ export declare function createExpressApp(options: {
9
9
  sslOptions?: HttpsConfig;
10
10
  setupCallback?: (app: Express, baseUrl: string) => void | Promise<void>;
11
11
  publicDir?: string;
12
+ middlewareMode?: boolean;
13
+ server?: Server;
12
14
  }): Promise<{
13
- server: Server;
15
+ app: Express;
16
+ server: Server | undefined;
14
17
  close: () => Promise<void>;
15
18
  url: string;
16
19
  baseUrl: string;
@@ -1 +1 @@
1
- {"version":3,"file":"createExpressApp.d.ts","sourceRoot":"","sources":["../src/createExpressApp.ts"],"names":[],"mappings":";AAAA,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAKhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG3E,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IAEZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CA2ED;AAED,YAAY,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"createExpressApp.d.ts","sourceRoot":"","sources":["../src/createExpressApp.ts"],"names":[],"mappings":";AAAA,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAKhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG3E,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,WAAW,CAAC;IAEzB,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC;IACV,GAAG,EAAE,OAAO,CAAC;IAEb,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IAEZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAoFD;AAED,YAAY,EAAE,OAAO,EAAE,CAAC"}
@@ -5,7 +5,7 @@ import compression from 'compression';
5
5
  import getPort from 'get-port';
6
6
  import { parseHttpsConfig } from './parseHttpsConfig.js';
7
7
  export async function createExpressApp(options) {
8
- const { setupCallback, hostname, sslOptions, requireSpecifiedPort, publicDir, portRange: ports } = options;
8
+ const { setupCallback, hostname, sslOptions, requireSpecifiedPort, publicDir, portRange: ports, middlewareMode, } = options;
9
9
  const portRange = typeof ports === 'number' ? [ports] : ports;
10
10
  if (requireSpecifiedPort && (portRange === undefined || portRange.length === 0)) {
11
11
  throw new Error('No port specified');
@@ -26,7 +26,7 @@ export async function createExpressApp(options) {
26
26
  app.use(express.static(publicDir, { index: false }));
27
27
  }
28
28
  const domain = hostname || 'localhost';
29
- let server;
29
+ let server = options.server;
30
30
  const protocol = sslOptions && Object.keys(sslOptions).length !== 0 ? 'https' : 'http';
31
31
  let url = `${protocol}://${domain}`;
32
32
  if ((protocol === 'https' && port !== 443) || (protocol === 'http' && port !== 80)) {
@@ -34,31 +34,32 @@ export async function createExpressApp(options) {
34
34
  }
35
35
  // Call setup callback with the app.
36
36
  await setupCallback?.(app, url);
37
- if (sslOptions && Object.keys(sslOptions).length !== 0) {
37
+ if (!middlewareMode && sslOptions && Object.keys(sslOptions).length !== 0) {
38
38
  // Create an HTTPS server.
39
39
  const httpsServer = https.createServer(parseHttpsConfig(sslOptions), app);
40
40
  server = httpsServer.listen(port, domain);
41
41
  }
42
- else {
42
+ else if (!middlewareMode) {
43
43
  // Create an HTTP server.
44
44
  server = app.listen(port, domain);
45
45
  }
46
46
  // Track the server connections.
47
47
  const sockets = new Set();
48
- server.on('connection', (socket) => {
48
+ server?.on('connection', (socket) => {
49
49
  sockets.add(socket);
50
50
  socket.on('close', () => {
51
51
  sockets.delete(socket);
52
52
  });
53
53
  });
54
54
  return {
55
+ app,
55
56
  server,
56
57
  async close() {
57
58
  for (const socket of sockets) {
58
59
  socket.destroy();
59
60
  }
60
61
  sockets.clear();
61
- await new Promise((resolve, reject) => server.close((err) => (err ? reject(err) : resolve())));
62
+ await new Promise((resolve, reject) => server?.close((err) => (err ? reject(err) : resolve())));
62
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O,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACtB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,MAAM;QACN,KAAK,CAAC,KAAK;YACT,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,MAAM,CAAC,OAAO,EAAE,CAAC;aAClB;YACD,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,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,CAAC;QACvG,CAAC;QACD,GAAG;QACH,OAAO,EAAE,GAAG;QACZ,QAAQ;QACR,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import express, { type Express } from 'express';\nimport https from 'https';\nimport cors from 'cors';\nimport compression from 'compression';\nimport getPort from 'get-port';\nimport type { Server } from 'http';\nimport { parseHttpsConfig, type HttpsConfig } from './parseHttpsConfig.js';\nimport type { Socket } from 'net';\n\nexport async function createExpressApp(options: {\n portRange?: number | number[];\n requireSpecifiedPort?: boolean;\n hostname?: string;\n sslOptions?: HttpsConfig;\n setupCallback?: (app: Express, baseUrl: string) => void | Promise<void>;\n publicDir?: string;\n}): Promise<{\n server: Server;\n close: () => Promise<void>;\n url: string;\n /* @deprecated - use url.*/\n baseUrl: string;\n protocol: 'http' | 'https';\n domain: string;\n port: number;\n}> {\n const { setupCallback, hostname, sslOptions, requireSpecifiedPort, publicDir, portRange: ports } = options;\n\n const portRange = typeof ports === 'number' ? [ports] : ports;\n\n if (requireSpecifiedPort && (portRange === undefined || portRange.length === 0)) {\n throw new Error('No port specified');\n }\n\n // Get the available port.\n const port = await getPort({\n port: portRange,\n });\n\n if (requireSpecifiedPort && portRange && !portRange.includes(port)) {\n throw new Error('Specified port not available');\n }\n\n const app = express();\n\n // Use cors.\n app.use(cors());\n\n // Use compression.\n app.use(compression());\n\n if (publicDir !== undefined) {\n app.use(express.static(publicDir, { index: false }));\n }\n\n const domain = hostname || 'localhost';\n let server: Server;\n const protocol = sslOptions && Object.keys(sslOptions).length !== 0 ? 'https' : 'http';\n let url = `${protocol}://${domain}`;\n\n if ((protocol === 'https' && port !== 443) || (protocol === 'http' && port !== 80)) {\n url += `:${port}`;\n }\n // Call setup callback with the app.\n await setupCallback?.(app, url);\n\n if (sslOptions && Object.keys(sslOptions).length !== 0) {\n // Create an HTTPS server.\n const httpsServer = https.createServer(parseHttpsConfig(sslOptions), app);\n server = httpsServer.listen(port, domain);\n } else {\n // Create an HTTP server.\n server = app.listen(port, domain);\n }\n\n // Track the server connections.\n const sockets = new Set<Socket>();\n\n server.on('connection', (socket) => {\n sockets.add(socket);\n socket.on('close', () => {\n sockets.delete(socket);\n });\n });\n\n return {\n server,\n async close() {\n for (const socket of sockets) {\n socket.destroy();\n }\n sockets.clear();\n await new Promise<void>((resolve, reject) => server.close((err) => (err ? reject(err) : resolve())));\n },\n url,\n baseUrl: url,\n protocol,\n domain,\n port,\n };\n}\n\nexport type { Express };\n"]}
1
+ {"version":3,"file":"createExpressApp.js","sourceRoot":"","sources":["../src/createExpressApp.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAgB,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAoB,MAAM,uBAAuB,CAAC;AAG3E,MAAM,CAAC,KAAK,UAAU,gBA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AAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QACxG,CAAC;QACD,GAAG;QACH,OAAO,EAAE,GAAG;QACZ,QAAQ;QACR,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import express, { type Express } from 'express';\nimport https from 'https';\nimport cors from 'cors';\nimport compression from 'compression';\nimport getPort from 'get-port';\nimport type { Server } from 'http';\nimport { parseHttpsConfig, type HttpsConfig } from './parseHttpsConfig.js';\nimport type { Socket } from 'net';\n\nexport async function createExpressApp(options: {\n portRange?: number | number[];\n requireSpecifiedPort?: boolean;\n hostname?: string;\n sslOptions?: HttpsConfig;\n /* @deprecated - use returned app.*/\n setupCallback?: (app: Express, baseUrl: string) => void | Promise<void>;\n publicDir?: string;\n middlewareMode?: boolean;\n server?: Server;\n}): Promise<{\n app: Express;\n /* The server will be undefined if middlewareMode is true and server is not provided. */\n server: Server | undefined;\n close: () => Promise<void>;\n url: string;\n /* @deprecated - use url.*/\n baseUrl: string;\n protocol: 'http' | 'https';\n domain: string;\n port: number;\n}> {\n const {\n setupCallback,\n hostname,\n sslOptions,\n requireSpecifiedPort,\n publicDir,\n portRange: ports,\n middlewareMode,\n } = options;\n\n const portRange = typeof ports === 'number' ? [ports] : ports;\n\n if (requireSpecifiedPort && (portRange === undefined || portRange.length === 0)) {\n throw new Error('No port specified');\n }\n\n // Get the available port.\n const port = await getPort({\n port: portRange,\n });\n\n if (requireSpecifiedPort && portRange && !portRange.includes(port)) {\n throw new Error('Specified port not available');\n }\n\n const app = express();\n\n // Use cors.\n app.use(cors());\n\n // Use compression.\n app.use(compression());\n\n if (publicDir !== undefined) {\n app.use(express.static(publicDir, { index: false }));\n }\n\n const domain = hostname || 'localhost';\n let server = options.server;\n const protocol = sslOptions && Object.keys(sslOptions).length !== 0 ? 'https' : 'http';\n let url = `${protocol}://${domain}`;\n\n if ((protocol === 'https' && port !== 443) || (protocol === 'http' && port !== 80)) {\n url += `:${port}`;\n }\n // Call setup callback with the app.\n await setupCallback?.(app, url);\n\n if (!middlewareMode && sslOptions && Object.keys(sslOptions).length !== 0) {\n // Create an HTTPS server.\n const httpsServer = https.createServer(parseHttpsConfig(sslOptions), app);\n server = httpsServer.listen(port, domain);\n } else if (!middlewareMode) {\n // Create an HTTP server.\n server = app.listen(port, domain);\n }\n\n // Track the server connections.\n const sockets = new Set<Socket>();\n\n server?.on('connection', (socket) => {\n sockets.add(socket);\n socket.on('close', () => {\n sockets.delete(socket);\n });\n });\n\n return {\n app,\n server,\n async close() {\n for (const socket of sockets) {\n socket.destroy();\n }\n sockets.clear();\n await new Promise<void>((resolve, reject) => server?.close((err) => (err ? reject(err) : resolve())));\n },\n url,\n baseUrl: url,\n protocol,\n domain,\n port,\n };\n}\n\nexport type { Express };\n"]}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as express from 'express';
2
- export type { Express, Request, Response } from 'express';
2
+ export type { Express, Request, Response, Router } from 'express';
3
3
  export { createExpressApp } from './createExpressApp.js';
4
4
  export { type HttpsConfig, parseHttpsConfig } from './parseHttpsConfig.js';
5
5
  export { express };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAoB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import * as express from 'express';\n\nexport type { Express, Request, Response } from 'express';\nexport { createExpressApp } from './createExpressApp.js';\nexport { type HttpsConfig, parseHttpsConfig } from './parseHttpsConfig.js';\nexport { express };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAoB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import * as express from 'express';\n\nexport type { Express, Request, Response, Router } from 'express';\nexport { createExpressApp } from './createExpressApp.js';\nexport { type HttpsConfig, parseHttpsConfig } from './parseHttpsConfig.js';\nexport { express };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"parseHttpsConfig.js","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAQrE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,MAAM,UAAU,GAAyC,EAAE,CAAC;IAE5D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,+CAA+C;QAC/C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3E,MAAM,YAAY,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;YAClD,IAAI,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;gBAC/B,qEAAqE;gBACrE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;aACjD;iBAAM;gBACL,MAAM,IAAI,KAAK,CACb,0EAA0E,YAAY,4EAA4E,CACnK,CAAC;aACH;SACF;aAAM;YACL,4CAA4C;YAC5C,UAAU,CAAC,GAAG,CAAC,GAAG,KAA6B,CAAC;SACjD;KACF;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import fs from 'fs';\nimport { pathSymbolReplacement } from '@ms-cloudpack/path-utilities';\nimport type { ServerOptions } from 'https';\nimport type { IncomingMessage, ServerResponse } from 'http';\n\ntype ValueOf<T> = T[keyof T];\n\nexport type HttpsConfig = ServerOptions<typeof IncomingMessage, typeof ServerResponse>;\n\n/*\n * Read certificates files in Https Config and return the contents.\n */\nexport function parseHttpsConfig(config: HttpsConfig): HttpsConfig {\n const sslOptions: Record<string, ValueOf<HttpsConfig>> = {};\n\n for (const [key, value] of Object.entries(config)) {\n // Read the file contents for the certificates.\n if (['ca', 'cert', 'key', 'pfx'].includes(key) && typeof value === 'string') {\n const certFilePath = pathSymbolReplacement(value);\n if (fs.existsSync(certFilePath)) {\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n sslOptions[key] = fs.readFileSync(certFilePath);\n } else {\n throw new Error(\n `The specified certificate to be used for the web server is missing at \"${certFilePath}\". Make sure the path is correct, the file exists, and try starting again.`,\n );\n }\n } else {\n // If not a certificate, just use the value.\n sslOptions[key] = value as ValueOf<HttpsConfig>;\n }\n }\n return sslOptions;\n}\n"]}
1
+ {"version":3,"file":"parseHttpsConfig.js","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAQrE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,MAAM,UAAU,GAAyC,EAAE,CAAC;IAE5D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,+CAA+C;QAC/C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5E,MAAM,YAAY,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;YAClD,IAAI,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;gBAChC,qEAAqE;gBACrE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YAClD,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,0EAA0E,YAAY,4EAA4E,CACnK,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,4CAA4C;YAC5C,UAAU,CAAC,GAAG,CAAC,GAAG,KAA6B,CAAC;QAClD,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import fs from 'fs';\nimport { pathSymbolReplacement } from '@ms-cloudpack/path-utilities';\nimport type { ServerOptions } from 'https';\nimport type { IncomingMessage, ServerResponse } from 'http';\n\ntype ValueOf<T> = T[keyof T];\n\nexport type HttpsConfig = ServerOptions<typeof IncomingMessage, typeof ServerResponse>;\n\n/*\n * Read certificates files in Https Config and return the contents.\n */\nexport function parseHttpsConfig(config: HttpsConfig): HttpsConfig {\n const sslOptions: Record<string, ValueOf<HttpsConfig>> = {};\n\n for (const [key, value] of Object.entries(config)) {\n // Read the file contents for the certificates.\n if (['ca', 'cert', 'key', 'pfx'].includes(key) && typeof value === 'string') {\n const certFilePath = pathSymbolReplacement(value);\n if (fs.existsSync(certFilePath)) {\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n sslOptions[key] = fs.readFileSync(certFilePath);\n } else {\n throw new Error(\n `The specified certificate to be used for the web server is missing at \"${certFilePath}\". Make sure the path is correct, the file exists, and try starting again.`,\n );\n }\n } else {\n // If not a certificate, just use the value.\n sslOptions[key] = value as ValueOf<HttpsConfig>;\n }\n }\n return sslOptions;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.38.3"
8
+ "packageVersion": "7.39.4"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/create-express-app",
3
- "version": "1.3.16",
3
+ "version": "1.4.0",
4
4
  "description": "Helper for creating an express app server, abstracting a common plugin setup.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/path-utilities": "^2.4.2",
17
+ "@ms-cloudpack/path-utilities": "^2.5.0",
18
18
  "@types/express": "^4.17.16",
19
19
  "compression": "^1.7.4",
20
20
  "cors": "^2.8.5",