@travetto/web-http 7.0.0-rc.7 → 7.0.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/README.md +2 -2
- package/package.json +4 -4
- package/support/cli.web_http.ts +10 -6
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ yarn add @travetto/web-http
|
|
|
16
16
|
This module provides basic for running [http](https://nodejs.org/api/http.html). [https](https://nodejs.org/api/https.html) and [http2](https://nodejs.org/api/http2.html) servers, along with support for tls key generation during development.
|
|
17
17
|
|
|
18
18
|
## Running a Server
|
|
19
|
-
By default, the framework provides a default [@CliCommand](https://github.com/travetto/travetto/tree/main/module/cli/src/registry/decorator.ts#
|
|
19
|
+
By default, the framework provides a default [@CliCommand](https://github.com/travetto/travetto/tree/main/module/cli/src/registry/decorator.ts#L98) for [WebHttpServer](https://github.com/travetto/travetto/tree/main/module/web-http/src/types.ts#L19) that will follow default behaviors, and spin up the server.
|
|
20
20
|
|
|
21
21
|
**Terminal: Standard application**
|
|
22
22
|
```bash
|
|
@@ -150,7 +150,7 @@ export class WebHttpConfig {
|
|
|
150
150
|
```
|
|
151
151
|
|
|
152
152
|
### Creating a Custom CLI Entry Point
|
|
153
|
-
To customize a Web server, you may need to construct an entry point using the [@CliCommand](https://github.com/travetto/travetto/tree/main/module/cli/src/registry/decorator.ts#
|
|
153
|
+
To customize a Web server, you may need to construct an entry point using the [@CliCommand](https://github.com/travetto/travetto/tree/main/module/cli/src/registry/decorator.ts#L98) decorator. This could look like:
|
|
154
154
|
|
|
155
155
|
**Code: Application entry point for Web Applications**
|
|
156
156
|
```typescript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web-http",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Web HTTP Server Support",
|
|
6
6
|
"keywords": [
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"directory": "module/web-http"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/web": "^7.0.
|
|
30
|
+
"@travetto/web": "^7.0.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/cli": "^7.0.
|
|
34
|
-
"@travetto/test": "^7.0.
|
|
33
|
+
"@travetto/cli": "^7.0.1",
|
|
34
|
+
"@travetto/test": "^7.0.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/test": {
|
package/support/cli.web_http.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Runtime, toConcrete
|
|
1
|
+
import { Runtime, toConcrete } from '@travetto/runtime';
|
|
2
2
|
import { DependencyRegistryIndex } from '@travetto/di';
|
|
3
3
|
import { CliCommand, CliCommandShape } from '@travetto/cli';
|
|
4
4
|
import { NetUtil } from '@travetto/web';
|
|
@@ -9,7 +9,7 @@ import type { WebHttpServer } from '../src/types.ts';
|
|
|
9
9
|
/**
|
|
10
10
|
* Run a web server
|
|
11
11
|
*/
|
|
12
|
-
@CliCommand({ runTarget: true, with: { debugIpc:
|
|
12
|
+
@CliCommand({ runTarget: true, with: { debugIpc: 'optional', restartOnChange: true, module: true, env: true } })
|
|
13
13
|
export class WebHttpCommand implements CliCommandShape {
|
|
14
14
|
|
|
15
15
|
/** Port to run on */
|
|
@@ -28,12 +28,16 @@ export class WebHttpCommand implements CliCommandShape {
|
|
|
28
28
|
await Registry.init();
|
|
29
29
|
const instance = await DependencyRegistryIndex.getInstance(toConcrete<WebHttpServer>());
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
const handle = await Util.acquireWithRetry(() => instance.serve(), NetUtil.freePortOnConflict, 5);
|
|
33
|
-
return handle.complete;
|
|
34
|
-
} else {
|
|
31
|
+
try {
|
|
35
32
|
const handle = await instance.serve();
|
|
36
33
|
return handle.complete;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
const result = this.killConflict ? await NetUtil.freePortOnConflict(err) : undefined;
|
|
36
|
+
if (result?.processId) {
|
|
37
|
+
console.warn('Killed process owning port', result);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
throw err;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
}
|