@ms-cloudpack/app-server 0.1.23 → 0.1.24
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/handleErrorPortUnavailable.d.ts +5 -0
- package/lib/handleErrorPortUnavailable.d.ts.map +1 -0
- package/lib/handleErrorPortUnavailable.js +17 -0
- package/lib/handleErrorPortUnavailable.js.map +1 -0
- package/lib/startAppServer.js +2 -2
- package/lib/startAppServer.js.map +1 -1
- package/package.json +6 -6
- package/lib/exitIfPortUnavailable.d.ts +0 -5
- package/lib/exitIfPortUnavailable.d.ts.map +0 -1
- package/lib/exitIfPortUnavailable.js +0 -14
- package/lib/exitIfPortUnavailable.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleErrorPortUnavailable.d.ts","sourceRoot":"","sources":["../src/handleErrorPortUnavailable.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAgBrG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handle the error if the port is already in use.
|
|
3
|
+
*/
|
|
4
|
+
export function handleErrorPortUnavailable(err, projectName, ports) {
|
|
5
|
+
const portRange = typeof ports === 'number' ? [ports] : ports;
|
|
6
|
+
if (err instanceof Error && err.message === 'Specified port not available') {
|
|
7
|
+
const portNeedsPrivileges = portRange.some((port) => port < 1024)
|
|
8
|
+
? '\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'
|
|
9
|
+
: '';
|
|
10
|
+
const errorMessage = `Cloudpack could not start "${projectName}" because no port from the allowed list was available: ${portRange.join(', ')}. Close other programs and try again.` + portNeedsPrivileges;
|
|
11
|
+
// Edit the error message to be more user-friendly.
|
|
12
|
+
err.message = errorMessage;
|
|
13
|
+
// Suppress the stack trace for this error because it's not useful to the user.
|
|
14
|
+
err.stack = undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=handleErrorPortUnavailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleErrorPortUnavailable.js","sourceRoot":"","sources":["../src/handleErrorPortUnavailable.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAY,EAAE,WAAmB,EAAE,KAAwB;IACpG,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,KAAK,8BAA8B,EAAE,CAAC;QAC3E,MAAM,mBAAmB,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;YAC/D,CAAC,CAAC,iKAAiK;YACnK,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,YAAY,GAChB,8BAA8B,WAAW,0DAA0D,SAAS,CAAC,IAAI,CAC/G,IAAI,CACL,uCAAuC,GAAG,mBAAmB,CAAC;QAEjE,mDAAmD;QACnD,GAAG,CAAC,OAAO,GAAG,YAAY,CAAC;QAC3B,+EAA+E;QAC/E,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["/**\n * Handle the error if the port is already in use.\n */\nexport function handleErrorPortUnavailable(err: unknown, projectName: string, ports: number | number[]) {\n const portRange = typeof ports === 'number' ? [ports] : ports;\n if (err instanceof Error && err.message === 'Specified port not available') {\n const portNeedsPrivileges = portRange.some((port) => port < 1024)\n ? '\\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'\n : '';\n const errorMessage =\n `Cloudpack could not start \"${projectName}\" because no port from the allowed list was available: ${portRange.join(\n ', ',\n )}. Close other programs and try again.` + portNeedsPrivileges;\n\n // Edit the error message to be more user-friendly.\n err.message = errorMessage;\n // Suppress the stack trace for this error because it's not useful to the user.\n err.stack = undefined;\n }\n}\n"]}
|
package/lib/startAppServer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createExpressApp } from '@ms-cloudpack/create-express-app';
|
|
2
2
|
import { createRoutes } from './createRoutes.js';
|
|
3
|
-
import {
|
|
3
|
+
import { handleErrorPortUnavailable } from './handleErrorPortUnavailable.js';
|
|
4
4
|
import { cyan } from '@ms-cloudpack/task-reporter';
|
|
5
5
|
/**
|
|
6
6
|
* The app server hosts the appropriate routes for the web app, primarily returning html content
|
|
@@ -51,7 +51,7 @@ export async function startAppServer({ session, bundleServer, apiServer, definit
|
|
|
51
51
|
}
|
|
52
52
|
catch (err) {
|
|
53
53
|
task.complete({ status: 'fail', message: 'Failed to start app server', forceShow: true });
|
|
54
|
-
|
|
54
|
+
handleErrorPortUnavailable(err, session.projectName, ports);
|
|
55
55
|
throw err;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,6B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ACJ,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/package-utilities';\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 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.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "An implementation of the App server for Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/api-server": "^0.30.
|
|
18
|
-
"@ms-cloudpack/bundle-server": "^0.2.
|
|
17
|
+
"@ms-cloudpack/api-server": "^0.30.6",
|
|
18
|
+
"@ms-cloudpack/bundle-server": "^0.2.21",
|
|
19
19
|
"@ms-cloudpack/bundler-types": "^0.24.1",
|
|
20
20
|
"@ms-cloudpack/config-types": "^0.4.3",
|
|
21
21
|
"@ms-cloudpack/create-express-app": "^1.4.0",
|
|
22
|
-
"@ms-cloudpack/overlay": "^0.16.
|
|
23
|
-
"@ms-cloudpack/package-hashes": "^0.3.
|
|
24
|
-
"@ms-cloudpack/package-utilities": "^5.10.
|
|
22
|
+
"@ms-cloudpack/overlay": "^0.16.70",
|
|
23
|
+
"@ms-cloudpack/package-hashes": "^0.3.23",
|
|
24
|
+
"@ms-cloudpack/package-utilities": "^5.10.1",
|
|
25
25
|
"@ms-cloudpack/path-string-parsing": "^1.1.3",
|
|
26
26
|
"@ms-cloudpack/path-utilities": "^2.5.0",
|
|
27
27
|
"@ms-cloudpack/task-reporter": "^0.11.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exitIfPortUnavailable.d.ts","sourceRoot":"","sources":["../src/exitIfPortUnavailable.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAehG"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Report the error and exit if the port is already in use.
|
|
3
|
-
*/
|
|
4
|
-
export function exitIfPortUnavailable(err, projectName, ports) {
|
|
5
|
-
const portRange = typeof ports === 'number' ? [ports] : ports;
|
|
6
|
-
if (err instanceof Error && err.message === 'Specified port not available') {
|
|
7
|
-
const portNeedsPrivileges = portRange.some((port) => port < 1024)
|
|
8
|
-
? '\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'
|
|
9
|
-
: '';
|
|
10
|
-
console.error(`Cloudpack could not start "${projectName}" because no port from the allowed list was available: ${portRange.join(', ')}. Close other programs and try again.`, portNeedsPrivileges);
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=exitIfPortUnavailable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exitIfPortUnavailable.js","sourceRoot":"","sources":["../src/exitIfPortUnavailable.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY,EAAE,WAAmB,EAAE,KAAwB;IAC/F,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,KAAK,8BAA8B,EAAE,CAAC;QAC3E,MAAM,mBAAmB,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;YAC/D,CAAC,CAAC,iKAAiK;YACnK,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,CAAC,KAAK,CACX,8BAA8B,WAAW,0DAA0D,SAAS,CAAC,IAAI,CAC/G,IAAI,CACL,uCAAuC,EACxC,mBAAmB,CACpB,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC","sourcesContent":["/**\n * Report the error and exit if the port is already in use.\n */\nexport function exitIfPortUnavailable(err: unknown, projectName: string, ports: number | number[]) {\n const portRange = typeof ports === 'number' ? [ports] : ports;\n if (err instanceof Error && err.message === 'Specified port not available') {\n const portNeedsPrivileges = portRange.some((port) => port < 1024)\n ? '\\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'\n : '';\n console.error(\n `Cloudpack could not start \"${projectName}\" because no port from the allowed list was available: ${portRange.join(\n ', ',\n )}. Close other programs and try again.`,\n portNeedsPrivileges,\n );\n\n process.exit(1);\n }\n}\n"]}
|