@ms-cloudpack/create-express-app 1.5.1 → 1.6.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
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type { HttpsConfig } from '@ms-cloudpack/
|
|
2
|
+
import type { HttpsConfig } from '@ms-cloudpack/common-types';
|
|
3
3
|
import { type Express } from 'express';
|
|
4
4
|
import type { Server } from 'http';
|
|
5
5
|
export declare function createExpressApp(options: {
|
package/lib/createExpressApp.js
CHANGED
|
@@ -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,MAAM,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"createExpressApp.js","sourceRoot":"","sources":["../src/createExpressApp.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAyB,MAAM,SAAS,CAAC;AAChD,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAWtC;IAYC,MAAM,EACJ,aAAa,EACb,QAAQ,EACR,cAAc,GAAG,EAAE,EACnB,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,SAAS,EAAE,KAAK,EAChB,cAAc,GACf,GAAG,OAAO,CAAC;IAEZ,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC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O;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,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 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 async function createExpressApp(options: {\n portRange?: number | number[];\n requireSpecifiedPort?: boolean;\n hostname?: string;\n requestHeaders?: Record<string, 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 requestHeaders = {},\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 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 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,10 +1,10 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
|
-
import type { HttpsConfig as _HttpsConfig } from '@ms-cloudpack/
|
|
2
|
+
import type { HttpsConfig as _HttpsConfig } from '@ms-cloudpack/common-types';
|
|
3
3
|
export type { Express, Request, Response, Router } from 'express';
|
|
4
4
|
export { createExpressApp } from './createExpressApp.js';
|
|
5
5
|
export { parseHttpsConfig } from './parseHttpsConfig.js';
|
|
6
6
|
export { getDomain } from './getDomain.js';
|
|
7
7
|
export { express };
|
|
8
|
-
/** @deprecated Import from `@ms-cloudpack/
|
|
8
|
+
/** @deprecated Import from `@ms-cloudpack/common-types` */
|
|
9
9
|
export type HttpsConfig = _HttpsConfig;
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
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;AAInC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import * as express from 'express';\nimport type { HttpsConfig as _HttpsConfig } from '@ms-cloudpack/
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import * as express from 'express';\nimport type { HttpsConfig as _HttpsConfig } from '@ms-cloudpack/common-types';\n\nexport type { Express, Request, Response, Router } from 'express';\nexport { createExpressApp } from './createExpressApp.js';\nexport { parseHttpsConfig } from './parseHttpsConfig.js';\nexport { getDomain } from './getDomain.js';\nexport { express };\n\n/** @deprecated Import from `@ms-cloudpack/common-types` */\nexport type HttpsConfig = _HttpsConfig;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseHttpsConfig.js","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAIrE;;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 type { HttpsConfig } from '@ms-cloudpack/
|
|
1
|
+
{"version":3,"file":"parseHttpsConfig.js","sourceRoot":"","sources":["../src/parseHttpsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAIrE;;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 type { HttpsConfig } from '@ms-cloudpack/common-types';\nimport { pathSymbolReplacement } from '@ms-cloudpack/path-utilities';\n\ntype ValueOf<T> = T[keyof T];\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/create-express-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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/
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.1.1",
|
|
18
18
|
"@ms-cloudpack/path-utilities": "^2.6.1",
|
|
19
19
|
"@types/express": "^4.17.16",
|
|
20
20
|
"compression": "^1.7.4",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"get-port": "^7.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@ms-cloudpack/eslint-plugin-internal": "
|
|
27
|
-
"@ms-cloudpack/scripts": "
|
|
28
|
-
"@ms-cloudpack/test-utilities": "
|
|
26
|
+
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
27
|
+
"@ms-cloudpack/scripts": "^0.0.1",
|
|
28
|
+
"@ms-cloudpack/test-utilities": "^0.5.0",
|
|
29
29
|
"@types/compression": "^1.7.2",
|
|
30
30
|
"@types/cors": "^2.8.13"
|
|
31
31
|
},
|