@travetto/web-http 8.0.0-alpha.2 → 8.0.0-alpha.21
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 +32 -4
- package/package.json +4 -4
- package/src/config.ts +2 -2
- package/support/cli.web_http.ts +9 -2
package/README.md
CHANGED
|
@@ -15,8 +15,36 @@ yarn add @travetto/web-http
|
|
|
15
15
|
|
|
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
|
+
## CLI - web:http
|
|
19
|
+
By default, the framework provides a default [@CliCommand](https://github.com/travetto/travetto/tree/main/module/cli/src/registry/decorator.ts#L20) 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
|
+
|
|
21
|
+
**Terminal: Help for web:http**
|
|
22
|
+
```bash
|
|
23
|
+
$ trv web:http --help
|
|
24
|
+
|
|
25
|
+
Usage: web:http [options]
|
|
26
|
+
|
|
27
|
+
Description:
|
|
28
|
+
Start the configured web HTTP server for a module.
|
|
29
|
+
|
|
30
|
+
Initializes registry and server bindings, supports restart-aware development
|
|
31
|
+
flags, and can attempt to clear conflicting port owners in local workflows.
|
|
32
|
+
|
|
33
|
+
Options:
|
|
34
|
+
-p, --port <number> Port to run on
|
|
35
|
+
--kill-conflict, --no-kill-conflict Kill conflicting port owner (default: true)
|
|
36
|
+
-m, --module <module> Module to run for
|
|
37
|
+
--profile <string> Application profiles
|
|
38
|
+
--restart-on-change, --no-restart-on-change Should the invocation automatically restart on source changes (default: true)
|
|
39
|
+
-d, --debug-ipc Should the invocation support debugging via IPC (e.g. from VSCode)
|
|
40
|
+
--help display help for command
|
|
41
|
+
|
|
42
|
+
Examples:
|
|
43
|
+
Starting a web server on port 8000
|
|
44
|
+
trv web:http -m <MODULE> -p 8000
|
|
45
|
+
```
|
|
46
|
+
|
|
18
47
|
## 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#L27) 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
48
|
|
|
21
49
|
**Terminal: Standard application**
|
|
22
50
|
```bash
|
|
@@ -139,8 +167,8 @@ export class WebHttpConfig {
|
|
|
139
167
|
this.tlsKeys = await WebTlsUtil.generateKeyPair();
|
|
140
168
|
} else {
|
|
141
169
|
if (this.tlsKeys.key.length < 100) { // We have files or resources
|
|
142
|
-
this.tlsKeys.key = await RuntimeResources.
|
|
143
|
-
this.tlsKeys.cert = await RuntimeResources.
|
|
170
|
+
this.tlsKeys.key = await RuntimeResources.readUTF8(this.tlsKeys.key);
|
|
171
|
+
this.tlsKeys.cert = await RuntimeResources.readUTF8(this.tlsKeys.cert);
|
|
144
172
|
}
|
|
145
173
|
}
|
|
146
174
|
|
|
@@ -150,7 +178,7 @@ export class WebHttpConfig {
|
|
|
150
178
|
```
|
|
151
179
|
|
|
152
180
|
### 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#
|
|
181
|
+
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#L20) decorator. This could look like:
|
|
154
182
|
|
|
155
183
|
**Code: Application entry point for Web Applications**
|
|
156
184
|
```typescript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web-http",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.21",
|
|
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": "^8.0.0-alpha.
|
|
30
|
+
"@travetto/web": "^8.0.0-alpha.20"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
34
|
-
"@travetto/test": "^8.0.0-alpha.
|
|
33
|
+
"@travetto/cli": "^8.0.0-alpha.25",
|
|
34
|
+
"@travetto/test": "^8.0.0-alpha.18"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/test": {
|
package/src/config.ts
CHANGED
|
@@ -62,8 +62,8 @@ export class WebHttpConfig {
|
|
|
62
62
|
this.tlsKeys = await WebTlsUtil.generateKeyPair();
|
|
63
63
|
} else {
|
|
64
64
|
if (this.tlsKeys.key.length < 100) { // We have files or resources
|
|
65
|
-
this.tlsKeys.key = await RuntimeResources.
|
|
66
|
-
this.tlsKeys.cert = await RuntimeResources.
|
|
65
|
+
this.tlsKeys.key = await RuntimeResources.readUTF8(this.tlsKeys.key);
|
|
66
|
+
this.tlsKeys.cert = await RuntimeResources.readUTF8(this.tlsKeys.cert);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
package/support/cli.web_http.ts
CHANGED
|
@@ -7,7 +7,14 @@ import { Registry } from '@travetto/registry';
|
|
|
7
7
|
import type { WebHttpServer } from '../src/types.ts';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Start the configured web HTTP server for a module.
|
|
11
|
+
*
|
|
12
|
+
* Initializes registry and server bindings, supports restart-aware development
|
|
13
|
+
* flags, and can attempt to clear conflicting port owners in local workflows.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* Starting a web server on port 8000
|
|
17
|
+
* > trv web:http -m <MODULE> -p 8000
|
|
11
18
|
*/
|
|
12
19
|
@CliCommand()
|
|
13
20
|
export class WebHttpCommand implements CliCommandShape {
|
|
@@ -25,7 +32,7 @@ export class WebHttpCommand implements CliCommandShape {
|
|
|
25
32
|
profile: string[];
|
|
26
33
|
|
|
27
34
|
@CliRestartOnChangeFlag()
|
|
28
|
-
restartOnChange: boolean =
|
|
35
|
+
restartOnChange: boolean = Runtime.localDevelopment;
|
|
29
36
|
|
|
30
37
|
@CliDebugIpcFlag()
|
|
31
38
|
debugIpc?: boolean;
|