@ms-cloudpack/create-express-app 1.7.5 → 1.8.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.
- package/lib/createExpressApp.d.ts +1 -1
- package/lib/createExpressApp.d.ts.map +1 -1
- package/lib/createExpressApp.js +2 -2
- package/lib/createExpressApp.js.map +1 -1
- package/lib/getDomain.d.ts +1 -1
- package/lib/getDomain.d.ts.map +1 -1
- package/lib/getDomain.js +4 -4
- package/lib/getDomain.js.map +1 -1
- package/lib/parseHttpsConfig.d.ts +5 -1
- package/lib/parseHttpsConfig.d.ts.map +1 -1
- package/lib/parseHttpsConfig.js +11 -2
- package/lib/parseHttpsConfig.js.map +1 -1
- package/package.json +4 -3
|
@@ -16,7 +16,7 @@ export interface CreateExpressAppOptions {
|
|
|
16
16
|
/** cwd for resolving any relative paths in `sslOptions` */
|
|
17
17
|
cwd?: string;
|
|
18
18
|
/** Options for an HTTPS server. Certificate paths support tokens `{homedir}` and `{tmpdir}`. */
|
|
19
|
-
sslOptions?: HttpsConfig;
|
|
19
|
+
sslOptions?: HttpsConfig | true;
|
|
20
20
|
/** @deprecated use returned `app` */
|
|
21
21
|
setupCallback?: (app: Express, baseUrl: string) => void | Promise<void>;
|
|
22
22
|
/** Path of any static assets */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExpressApp.d.ts","sourceRoot":"","sources":["../src/createExpressApp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAG9D,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAMnC,MAAM,WAAW,uBAAuB;IACtC,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,kFAAkF;IAClF,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC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b,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAuGxG;AAED,YAAY,EAAE,OAAO,EAAE,CAAC"}
|
package/lib/createExpressApp.js
CHANGED
|
@@ -39,7 +39,7 @@ export async function createExpressApp(options) {
|
|
|
39
39
|
}
|
|
40
40
|
const domain = getDomain(hostname);
|
|
41
41
|
let server = options.server;
|
|
42
|
-
const isHttps = !!sslOptions
|
|
42
|
+
const isHttps = !!sslOptions;
|
|
43
43
|
const protocol = isHttps ? 'https' : 'http';
|
|
44
44
|
let url = `${protocol}://${domain}`;
|
|
45
45
|
if ((isHttps && port !== 443) || (!isHttps && port !== 80)) {
|
|
@@ -50,7 +50,7 @@ export async function createExpressApp(options) {
|
|
|
50
50
|
if (!server) {
|
|
51
51
|
if (isHttps) {
|
|
52
52
|
// Create an HTTPS server.
|
|
53
|
-
const httpsServer = https.createServer(parseHttpsConfig(sslOptions, cwd), app);
|
|
53
|
+
const httpsServer = https.createServer(await parseHttpsConfig({ domain, https: sslOptions, cwd }), app);
|
|
54
54
|
server = httpsServer.listen(port, domain);
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExpressApp.js","sourceRoot":"","sources":["../src/createExpressApp.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,IAAI,MAAM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,EAAE,EAAE;QACjC,OAAO,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,GAAG;QACH,MAAM;QACN,KAAK,CAAC,KAAK;YACT,KAAK,MAAM,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;gBAC1C,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;YACzD,CAAC,CAAC,CAAC;QACL,CAAC;QACD,GAAG;QACH,OAAO,EAAE,GAAG;QACZ,QAAQ;QACR,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import type { HttpsConfig } from '@ms-cloudpack/common-types';\nimport compression from 'compression';\nimport cors from 'cors';\nimport express, { type Express } from 'express';\nimport getPort from 'get-port';\nimport type { Server } from 'http';\nimport https from 'https';\nimport type { Socket } from 'net';\nimport { parseHttpsConfig } from './parseHttpsConfig.js';\nimport { getDomain } from './getDomain.js';\n\nexport interface CreateExpressAppOptions {\n /** Port(s) to try */\n portRange?: number | number[];\n /** Throw an error if none of the ports specified in `portRange` are available. */\n requireSpecifiedPort?: boolean;\n /**\n * Hostname to use for the server. Supports replacement `{ip}` for the current IP address.\n * @default 'localhost'\n */\n hostname?: string;\n /** Include these headers with all responses */\n requestHeaders?: Record<string, string>;\n /** cwd for resolving any relative paths in `sslOptions` */\n cwd?: string;\n /** Options for an HTTPS server. Certificate paths support tokens `{homedir}` and `{tmpdir}`. */\n sslOptions?: HttpsConfig | true;\n /** @deprecated use returned `app` */\n setupCallback?: (app: Express, baseUrl: string) => void | Promise<void>;\n /** Path of any static assets */\n publicDir?: string;\n /** @deprecated Inferred based on presence of `server` */\n middlewareMode?: boolean;\n /** If provided, act as a middleware on this server, rather than starting a new server */\n server?: Server;\n}\n\nexport interface CreateExpressAppResult {\n app: Express;\n /** http or https server */\n server: Server;\n /** Close the server */\n close: () => Promise<void>;\n /** Base URL of the app */\n url: string;\n /** @deprecated use `url` */\n baseUrl: string;\n protocol: 'http' | 'https';\n /** Domain (no protocol or port) the app is running on */\n domain: string;\n /** Port the app is running on */\n port: number;\n}\n\nexport async function createExpressApp(options: CreateExpressAppOptions): Promise<CreateExpressAppResult> {\n const {\n // eslint-disable-next-line etc/no-deprecated\n setupCallback,\n hostname,\n requestHeaders = {},\n cwd = '',\n sslOptions,\n requireSpecifiedPort,\n publicDir,\n portRange: ports,\n } = options;\n\n if (sslOptions && !cwd) {\n throw new Error('Must provide `cwd` when `sslOptions` are provided');\n }\n\n const portRange = typeof ports === 'number' ? [ports] : ports;\n\n if (requireSpecifiedPort && !portRange?.length) {\n throw new Error('Must specify a portRange when requireSpecifiedPort is true');\n }\n\n // Get the available port.\n const port = await getPort({\n port: portRange,\n });\n\n if (requireSpecifiedPort && !portRange?.includes(port)) {\n throw new Error(`No ports from portRange ${JSON.stringify(portRange)} are 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 app.use((_, res, next) => {\n for (const [headerName, headerValue] of Object.entries(requestHeaders)) {\n res.setHeader(headerName, headerValue);\n }\n next();\n });\n\n if (publicDir !== undefined) {\n app.use(express.static(publicDir, { index: false }));\n }\n\n const domain = getDomain(hostname);\n let server = options.server;\n const isHttps = !!sslOptions;\n const protocol = isHttps ? 'https' : 'http';\n let url = `${protocol}://${domain}`;\n\n if ((isHttps && port !== 443) || (!isHttps && port !== 80)) {\n url += `:${port}`;\n }\n // Call setup callback with the app.\n await setupCallback?.(app, url);\n\n if (!server) {\n if (isHttps) {\n // Create an HTTPS server.\n const httpsServer = https.createServer(await parseHttpsConfig({ domain, https: sslOptions, cwd }), app);\n server = httpsServer.listen(port, domain);\n } else {\n // Create an HTTP server.\n server = app.listen(port, domain);\n }\n }\n\n // Track new connections so that we can close them and exit cleanly on ctrl+C.\n // (Calling close() on an express server simply stops it from accepting new connections;\n // it doesn't close existing keep-alive connections, which makes the CLI hang on exit.)\n const sockets = new Set<Socket>();\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) => {\n server.close((err) => (err ? reject(err) : resolve()));\n });\n },\n url,\n baseUrl: url,\n protocol,\n domain,\n port,\n };\n}\n\nexport type { Express };\n"]}
|
package/lib/getDomain.d.ts
CHANGED
package/lib/getDomain.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDomain.d.ts","sourceRoot":"","sources":["../src/getDomain.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"getDomain.d.ts","sourceRoot":"","sources":["../src/getDomain.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAM5D"}
|
package/lib/getDomain.js
CHANGED
|
@@ -9,11 +9,11 @@ const addressSymbols = {
|
|
|
9
9
|
* Defaults to 'localhost'.
|
|
10
10
|
* @returns The domain (no protocol)
|
|
11
11
|
*/
|
|
12
|
-
export function getDomain(
|
|
13
|
-
|
|
12
|
+
export function getDomain(domain) {
|
|
13
|
+
const primaryDomain = Array.isArray(domain) ? domain[0] : domain;
|
|
14
|
+
if (!primaryDomain)
|
|
14
15
|
return 'localhost';
|
|
15
|
-
|
|
16
|
-
return str.replace(/{(\w+)}/g, (match, symbol) => addressSymbols[symbol]() || match);
|
|
16
|
+
return primaryDomain.replace(/{(\w+)}/g, (match, symbol) => addressSymbols[symbol]() || match);
|
|
17
17
|
}
|
|
18
18
|
function getLocalIP() {
|
|
19
19
|
const networkInterfaces = os.networkInterfaces();
|
package/lib/getDomain.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDomain.js","sourceRoot":"","sources":["../src/getDomain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,6BAA6B;AAC7B,6DAA6D;AAC7D,MAAM,cAAc,GAAiC;IACnD,EAAE,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"getDomain.js","sourceRoot":"","sources":["../src/getDomain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,6BAA6B;AAC7B,6DAA6D;AAC7D,MAAM,cAAc,GAAiC;IACnD,EAAE,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAA0B;IAClD,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAEjE,IAAI,CAAC,aAAa;QAAE,OAAO,WAAW,CAAC;IAEvC,OAAO,aAAa,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAc,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,CAAC,CAAC;AACzG,CAAC;AAED,SAAS,UAAU;IACjB,MAAM,iBAAiB,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC;IAEjD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACpD,6DAA6D;QAC7D,MAAM,GAAG,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAClE,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,GAAG,CAAC,OAAO,CAAC;QACrB,CAAC;IACH,CAAC;IAED,mEAAmE;IACnE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import os from 'os';\n\n// Supported address symbols:\n// These are functions to not call them if they are not used.\nconst addressSymbols: Record<string, () => string> = {\n ip: () => getLocalIP(),\n};\n\n/**\n * Get the domain from the given string, replacing the `{ip}` symbol with the current IP.\n * Defaults to 'localhost'.\n * @returns The domain (no protocol)\n */\nexport function getDomain(domain?: string | string[]): string {\n const primaryDomain = Array.isArray(domain) ? domain[0] : domain;\n\n if (!primaryDomain) return 'localhost';\n\n return primaryDomain.replace(/{(\\w+)}/g, (match, symbol: string) => addressSymbols[symbol]() || match);\n}\n\nfunction getLocalIP(): string {\n const networkInterfaces = os.networkInterfaces();\n\n for (const nets of Object.values(networkInterfaces)) {\n // Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses\n const net = nets?.find((n) => n.family === 'IPv4' && !n.internal);\n if (net) {\n return net.address;\n }\n }\n\n // Throw an error to avoid creating a server with an unexpected URL\n throw new Error('Failed to get local IP address.');\n}\n"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { HttpsConfig } from '@ms-cloudpack/common-types';
|
|
2
|
-
export declare function parseHttpsConfig(
|
|
2
|
+
export declare function parseHttpsConfig(options: {
|
|
3
|
+
domain?: string;
|
|
4
|
+
https: true | HttpsConfig;
|
|
5
|
+
cwd: string;
|
|
6
|
+
}): Promise<HttpsConfig>;
|
|
3
7
|
//# sourceMappingURL=parseHttpsConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseHttpsConfig.d.ts","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"parseHttpsConfig.d.ts","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAU9D,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CAoCvB"}
|
package/lib/parseHttpsConfig.js
CHANGED
|
@@ -2,12 +2,21 @@ import path from 'path';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { pathSymbolReplacement } from '@ms-cloudpack/path-utilities';
|
|
4
4
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
5
|
+
import { getCertificate } from '@ms-cloudpack/setup-utilities';
|
|
5
6
|
/*
|
|
6
7
|
* Read certificates files in Https Config and return the contents.
|
|
7
8
|
*/
|
|
8
|
-
export function parseHttpsConfig(
|
|
9
|
+
export async function parseHttpsConfig(options) {
|
|
10
|
+
const { https, cwd } = options;
|
|
11
|
+
if (https === true) {
|
|
12
|
+
const httpsConfig = await getCertificate(options);
|
|
13
|
+
if (!httpsConfig) {
|
|
14
|
+
throw new Error(`No certificate found for the domain "${options.domain}". Make sure you have a valid certificate in the cloudpack.config.json file.`);
|
|
15
|
+
}
|
|
16
|
+
return httpsConfig;
|
|
17
|
+
}
|
|
9
18
|
const sslOptions = {};
|
|
10
|
-
for (const [key, value] of Object.entries(
|
|
19
|
+
for (const [key, value] of Object.entries(https)) {
|
|
11
20
|
// Read the file contents for the certificates.
|
|
12
21
|
if (['ca', 'cert', 'key', 'pfx'].includes(key) && typeof value === 'string') {
|
|
13
22
|
// Get a standard path with expanded path symbols.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseHttpsConfig.js","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"parseHttpsConfig.js","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAI/D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAItC;IACC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAE/B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;QAElD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,wCAAwC,OAAO,CAAC,MAAM,8EAA8E,CACrI,CAAC;QACJ,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,UAAU,GAAyC,EAAE,CAAC;IAE5D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;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,CAAC;YAC5E,kDAAkD;YAClD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAE5E,IAAI,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;gBAChC,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 path from 'path';\nimport fs from 'fs';\nimport type { HttpsConfig } from '@ms-cloudpack/common-types';\nimport { pathSymbolReplacement } from '@ms-cloudpack/path-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { getCertificate } from '@ms-cloudpack/setup-utilities';\n\ntype ValueOf<T> = T[keyof T];\n\n/*\n * Read certificates files in Https Config and return the contents.\n */\nexport async function parseHttpsConfig(options: {\n domain?: string;\n https: true | HttpsConfig;\n cwd: string;\n}): Promise<HttpsConfig> {\n const { https, cwd } = options;\n\n if (https === true) {\n const httpsConfig = await getCertificate(options);\n\n if (!httpsConfig) {\n throw new Error(\n `No certificate found for the domain \"${options.domain}\". Make sure you have a valid certificate in the cloudpack.config.json file.`,\n );\n }\n\n return httpsConfig;\n }\n\n const sslOptions: Record<string, ValueOf<HttpsConfig>> = {};\n\n for (const [key, value] of Object.entries(https)) {\n // Read the file contents for the certificates.\n if (['ca', 'cert', 'key', 'pfx'].includes(key) && typeof value === 'string') {\n // Get a standard path with expanded path symbols.\n const certFilePath = slash(path.resolve(cwd, pathSymbolReplacement(value)));\n\n if (fs.existsSync(certFilePath)) {\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/create-express-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Helper for creating an express app server, abstracting a common plugin setup.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.18.0",
|
|
18
18
|
"@ms-cloudpack/path-string-parsing": "^1.2.4",
|
|
19
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
19
|
+
"@ms-cloudpack/path-utilities": "^2.7.36",
|
|
20
|
+
"@ms-cloudpack/setup-utilities": "^0.1.2",
|
|
20
21
|
"@types/express": "^4.17.16",
|
|
21
22
|
"compression": "^1.7.4",
|
|
22
23
|
"cors": "^2.8.5",
|