@jixo/opendweb-server-binary 0.1.0 → 0.2.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.
- package/bin/dweb-server-aarch64-apple-darwin +0 -0
- package/index.d.ts +11 -1
- package/index.js +26 -9
- package/package.json +1 -1
|
Binary file
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
export interface StartServerOptions {
|
|
2
|
-
/** rendezvous/healthz
|
|
2
|
+
/** gateway(rendezvous/healthz/services.json)监听地址,默认 127.0.0.1:8787 */
|
|
3
|
+
gatewayBind?: string;
|
|
4
|
+
/** gatewayBind 的兼容别名(同时给出时 gatewayBind 优先) */
|
|
3
5
|
httpBind?: string;
|
|
4
6
|
/** relay HTTP 监听地址,默认 127.0.0.1:3340 */
|
|
5
7
|
relayBind?: string;
|
|
6
8
|
/** 默认 true */
|
|
7
9
|
relayEnabled?: boolean;
|
|
10
|
+
/** true 时向子进程设置 DWEB_TRUST_PROXY=1(采信 X-Forwarded-Proto);缺省继承父进程环境 */
|
|
11
|
+
trustProxy?: boolean;
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
export interface ServerHandle {
|
|
11
15
|
pid: number;
|
|
16
|
+
/** gateway 基地址 */
|
|
17
|
+
gatewayUrl: string;
|
|
18
|
+
/** 旧字段名保留(值同 gatewayUrl) */
|
|
12
19
|
httpUrl: string;
|
|
20
|
+
/** relay HTTP 基地址 */
|
|
13
21
|
relayHttpUrl: string;
|
|
22
|
+
/** 服务清单地址(GET /services.json) */
|
|
23
|
+
servicesUrl: string;
|
|
14
24
|
/** 发送 SIGINT 并等待退出(5s 后 SIGKILL 兜底),幂等 */
|
|
15
25
|
stop(): Promise<void>;
|
|
16
26
|
/** 进程退出码 future */
|
package/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
// @dweb/server-binary:以子进程方式启动 dweb-server
|
|
1
|
+
// @dweb/server-binary:以子进程方式启动 dweb-server,提供可等待的停止方式。
|
|
2
|
+
// gateway 命名(design D1):gatewayBind 为 canonical,httpBind 为兼容别名;
|
|
3
|
+
// 透传 DWEB_GATEWAY_BIND / DWEB_TRUST_PROXY 等环境变量。
|
|
2
4
|
import { spawn } from "node:child_process";
|
|
3
5
|
import { createHash } from "node:crypto";
|
|
4
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -14,21 +16,24 @@ const SUPPORTED = `${process.platform}-${process.arch}`;
|
|
|
14
16
|
const BINARY_NAME = PLATFORM_BINARIES[SUPPORTED];
|
|
15
17
|
if (!BINARY_NAME) {
|
|
16
18
|
throw new Error(
|
|
17
|
-
`@jixo/opendweb-server-binary:
|
|
19
|
+
`@jixo/opendweb-server-binary: platform ${SUPPORTED} is not supported yet. v0.2 ships ${Object.keys(PLATFORM_BINARIES).join(" / ")}; use the docker image ghcr.io/gaubee/dweb for other platforms.`,
|
|
18
20
|
);
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* @typedef {Object} StartServerOptions
|
|
23
|
-
* @property {string} [
|
|
24
|
-
* @property {string} [
|
|
25
|
+
* @property {string} [gatewayBind] gateway(rendezvous/healthz/services.json)监听地址,默认 127.0.0.1:8787
|
|
26
|
+
* @property {string} [httpBind] gatewayBind 的兼容别名(同时给出时 gatewayBind 优先)
|
|
27
|
+
* @property {string} [relayBind] relay HTTP 监听地址,默认 127.0.0.1:3340
|
|
25
28
|
* @property {boolean} [relayEnabled] 默认 true
|
|
29
|
+
* @property {boolean} [trustProxy] true 时向子进程设置 DWEB_TRUST_PROXY=1(采信 X-Forwarded-Proto);
|
|
30
|
+
* false 时设为 "0";缺省时继承父进程环境
|
|
26
31
|
*/
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* 启动 dweb-server 子进程。
|
|
30
35
|
* @param {StartServerOptions} [options]
|
|
31
|
-
* @returns {Promise<{ pid: number, httpUrl: string, relayHttpUrl: string, stop: () => Promise<void>, exited: Promise<number> }>}
|
|
36
|
+
* @returns {Promise<{ pid: number, gatewayUrl: string, httpUrl: string, relayHttpUrl: string, servicesUrl: string, stop: () => Promise<void>, exited: Promise<number> }>}
|
|
32
37
|
*/
|
|
33
38
|
export async function startServer(options = {}) {
|
|
34
39
|
const binDir = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -56,14 +61,17 @@ export async function startServer(options = {}) {
|
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
const
|
|
64
|
+
const gatewayBind = options.gatewayBind ?? options.httpBind ?? "127.0.0.1:8787";
|
|
60
65
|
const relayBind = options.relayBind ?? "127.0.0.1:3340";
|
|
61
66
|
const env = {
|
|
62
67
|
...process.env,
|
|
63
|
-
|
|
68
|
+
DWEB_GATEWAY_BIND: gatewayBind,
|
|
64
69
|
DWEB_RELAY_HTTP_BIND: relayBind,
|
|
65
70
|
DWEB_RELAY_ENABLED: options.relayEnabled === false ? "false" : "true",
|
|
66
71
|
};
|
|
72
|
+
if (options.trustProxy !== undefined) {
|
|
73
|
+
env.DWEB_TRUST_PROXY = options.trustProxy ? "1" : "0";
|
|
74
|
+
}
|
|
67
75
|
|
|
68
76
|
const child = spawn(binPath, [], { env, stdio: ["ignore", "pipe", "pipe"] });
|
|
69
77
|
if (typeof child.pid !== "number") {
|
|
@@ -85,7 +93,16 @@ export async function startServer(options = {}) {
|
|
|
85
93
|
}, 5000).unref();
|
|
86
94
|
});
|
|
87
95
|
|
|
88
|
-
const
|
|
96
|
+
const gatewayUrl = `http://${gatewayBind}`;
|
|
89
97
|
const relayHttpUrl = `http://${relayBind}`;
|
|
90
|
-
|
|
98
|
+
// httpUrl 为旧字段名保留(值同 gatewayUrl)
|
|
99
|
+
return {
|
|
100
|
+
pid: child.pid,
|
|
101
|
+
gatewayUrl,
|
|
102
|
+
httpUrl: gatewayUrl,
|
|
103
|
+
relayHttpUrl,
|
|
104
|
+
servicesUrl: `${gatewayUrl}/services.json`,
|
|
105
|
+
stop,
|
|
106
|
+
exited,
|
|
107
|
+
};
|
|
91
108
|
}
|
package/package.json
CHANGED