@vibecook/truffle 0.7.0 → 0.7.2
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/dist/create-mesh-node.d.ts +46 -0
- package/dist/create-mesh-node.d.ts.map +1 -1
- package/dist/create-mesh-node.js +23 -2
- package/dist/create-mesh-node.js.map +1 -1
- package/dist/http.d.ts +50 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +100 -11
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/net.d.ts +45 -4
- package/dist/net.d.ts.map +1 -1
- package/dist/net.js +45 -8
- package/dist/net.js.map +1 -1
- package/dist/serve.d.ts +142 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +347 -0
- package/dist/serve.js.map +1 -0
- package/dist/ws.d.ts +8 -1
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js +14 -17
- package/dist/ws.js.map +1 -1
- package/package.json +7 -7
- package/sidecar-checksums.json +14 -0
package/dist/net.js
CHANGED
|
@@ -22,14 +22,22 @@ export class TruffleSocket extends Duplex {
|
|
|
22
22
|
#native = null;
|
|
23
23
|
#ready;
|
|
24
24
|
#reading = false;
|
|
25
|
+
#resolvePeer;
|
|
25
26
|
/** Logical remote address (`host:port`); set once connected. */
|
|
26
27
|
remoteAddress;
|
|
27
28
|
/** Stable peer id (resolved device id, or WhoIs node id inbound) when known. */
|
|
28
29
|
remotePeerId;
|
|
29
30
|
/** Human-readable peer name from the WhoIs identity (inbound sockets). */
|
|
30
31
|
remotePeerName;
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* True on sockets accepted by a `tls: true` mesh listener (TLS terminated
|
|
34
|
+
* in the sidecar). This is the undocumented-but-universal property http
|
|
35
|
+
* frameworks sniff for `req.secure` / `req.protocol === 'https'`.
|
|
36
|
+
*/
|
|
37
|
+
encrypted;
|
|
38
|
+
constructor(native, hooks) {
|
|
32
39
|
super({ allowHalfOpen: true });
|
|
40
|
+
this.#resolvePeer = hooks?.resolvePeer;
|
|
33
41
|
const adopt = (sock) => {
|
|
34
42
|
this.#native = sock;
|
|
35
43
|
this.remoteAddress = sock.remoteAddress();
|
|
@@ -149,6 +157,19 @@ export class TruffleSocket extends Duplex {
|
|
|
149
157
|
address() {
|
|
150
158
|
return {};
|
|
151
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* The interned RFC 022 `Peer` handle for the remote end, resolved live from
|
|
162
|
+
* the mesh node's registry by this socket's `remotePeerId`. Null when the
|
|
163
|
+
* id is not yet known (dial in flight), the peer isn't interned, or the
|
|
164
|
+
* namespace was built without registry hooks (outside `createMeshNode`).
|
|
165
|
+
* Inbound sockets have it from accept time — use it for gating:
|
|
166
|
+
* `req.socket.remotePeer?.displayName`.
|
|
167
|
+
*/
|
|
168
|
+
get remotePeer() {
|
|
169
|
+
if (!this.remotePeerId || !this.#resolvePeer)
|
|
170
|
+
return null;
|
|
171
|
+
return this.#resolvePeer(this.remotePeerId) ?? null;
|
|
172
|
+
}
|
|
152
173
|
}
|
|
153
174
|
/**
|
|
154
175
|
* A TCP server on the mesh, mimicking `net.Server`.
|
|
@@ -168,11 +189,15 @@ export class TruffleServer extends EventEmitter {
|
|
|
168
189
|
#listener = null;
|
|
169
190
|
#closed = false;
|
|
170
191
|
#closeEmitted = false;
|
|
192
|
+
#hooks;
|
|
193
|
+
#tls;
|
|
171
194
|
/** Bound port; set once `'listening'` fires (resolved when 0 was requested). */
|
|
172
195
|
port;
|
|
173
|
-
constructor(node, connectionListener) {
|
|
196
|
+
constructor(node, connectionListener, options) {
|
|
174
197
|
super();
|
|
175
198
|
this.#node = node;
|
|
199
|
+
this.#hooks = options?.hooks;
|
|
200
|
+
this.#tls = options?.tls ?? false;
|
|
176
201
|
if (connectionListener)
|
|
177
202
|
this.on('connection', connectionListener);
|
|
178
203
|
}
|
|
@@ -185,8 +210,10 @@ export class TruffleServer extends EventEmitter {
|
|
|
185
210
|
throw new Error('listen() already called');
|
|
186
211
|
if (listeningListener)
|
|
187
212
|
this.once('listening', listeningListener);
|
|
188
|
-
|
|
189
|
-
|
|
213
|
+
// The tls parameter is the RFC 023 P2 native signature; pre-P2 natives
|
|
214
|
+
// (and test mocks written against the one-arg form) ignore extra args.
|
|
215
|
+
const listenTcp = this.#node.listenTcp.bind(this.#node);
|
|
216
|
+
listenTcp(port, this.#tls ? true : undefined)
|
|
190
217
|
.then((listener) => {
|
|
191
218
|
if (this.#closed) {
|
|
192
219
|
void listener.close();
|
|
@@ -206,7 +233,12 @@ export class TruffleServer extends EventEmitter {
|
|
|
206
233
|
const native = await listener.accept();
|
|
207
234
|
if (native === null)
|
|
208
235
|
break;
|
|
209
|
-
|
|
236
|
+
const socket = new TruffleSocket(native, this.#hooks);
|
|
237
|
+
// TLS terminated in the sidecar → mark the socket the way frameworks
|
|
238
|
+
// sniff it (req.secure); see TruffleSocket.encrypted.
|
|
239
|
+
if (this.#tls)
|
|
240
|
+
socket.encrypted = true;
|
|
241
|
+
this.emit('connection', socket);
|
|
210
242
|
}
|
|
211
243
|
}
|
|
212
244
|
catch (err) {
|
|
@@ -261,16 +293,21 @@ function resolveConnectTarget(options) {
|
|
|
261
293
|
}
|
|
262
294
|
return peerLikeToQuery(target);
|
|
263
295
|
}
|
|
264
|
-
export function createNetNamespace(node) {
|
|
296
|
+
export function createNetNamespace(node, hooks) {
|
|
265
297
|
function connect(optionsOrPort, maybeHost) {
|
|
266
298
|
const opts = typeof optionsOrPort === 'number' ? { host: maybeHost, port: optionsOrPort } : optionsOrPort;
|
|
267
299
|
const host = resolveConnectTarget(opts);
|
|
268
|
-
return new TruffleSocket(node.openTcp(host, opts.port));
|
|
300
|
+
return new TruffleSocket(node.openTcp(host, opts.port), hooks);
|
|
301
|
+
}
|
|
302
|
+
function createServer(arg1, arg2) {
|
|
303
|
+
const options = typeof arg1 === 'object' && arg1 !== null ? arg1 : {};
|
|
304
|
+
const listener = typeof arg1 === 'function' ? arg1 : arg2;
|
|
305
|
+
return new TruffleServer(node, listener, { ...options, hooks });
|
|
269
306
|
}
|
|
270
307
|
return {
|
|
271
308
|
connect,
|
|
272
309
|
createConnection: connect,
|
|
273
|
-
createServer
|
|
310
|
+
createServer,
|
|
274
311
|
};
|
|
275
312
|
}
|
|
276
313
|
//# sourceMappingURL=net.js.map
|
package/dist/net.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.js","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,sEAAsE;AACtE,sDAAsD;AACtD,0EAA0E;AAC1E,gEAAgE;AAChE,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,aAAa;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"net.js","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,sEAAsE;AACtE,sDAAsD;AACtD,0EAA0E;AAC1E,gEAAgE;AAChE,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,aAAa;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,eAAe,EAA4B,MAAM,WAAW,CAAC;AA6CtE;;;;;;GAMG;AACH,MAAM,OAAO,aAAc,SAAQ,MAAM;IACvC,OAAO,GAAyB,IAAI,CAAC;IACrC,MAAM,CAAyB;IAC/B,QAAQ,GAAG,KAAK,CAAC;IACjB,YAAY,CAA2B;IAEvC,gEAAgE;IAChE,aAAa,CAAU;IACvB,gFAAgF;IAChF,YAAY,CAAU;IACtB,0EAA0E;IAC1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ProxyConfig } from '@vibecook/truffle-native';
|
|
3
|
+
/** Options common to every {@link ServeConfig} shape. */
|
|
4
|
+
export interface ServeOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Terminate TLS in the sidecar with automatic MagicDNS certificates.
|
|
7
|
+
* Default **true** — the serve audience is browsers (padlock, secure
|
|
8
|
+
* context, `wss:`), and it preserves the shipped engine behavior. `false`
|
|
9
|
+
* serves plain HTTP (WireGuard still encrypts the tailnet hop). Requires
|
|
10
|
+
* MagicDNS + HTTPS enabled on the tailnet; the cert matches only the full
|
|
11
|
+
* `.ts.net` FQDN — use {@link ServeHandle.url} / `mesh.dnsName` in links.
|
|
12
|
+
*/
|
|
13
|
+
tls?: boolean;
|
|
14
|
+
/** Human-readable label. Defaults to {@link id}. */
|
|
15
|
+
name?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Stable proxy id, unique per node. Defaults to `serve-${port}`, so two
|
|
18
|
+
* serves on the same port collide unless you set distinct ids.
|
|
19
|
+
*/
|
|
20
|
+
id?: string;
|
|
21
|
+
/**
|
|
22
|
+
* loginName allow globs, e.g. `["*@corp.com"]`. Absent = the whole tailnet.
|
|
23
|
+
* A non-matching caller gets a bare 403. Per-route `allow` overrides this
|
|
24
|
+
* (RFC 023 §9.7).
|
|
25
|
+
*/
|
|
26
|
+
allow?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Permit non-loopback targets (default false = deny). A LAN target turns
|
|
29
|
+
* this node into a pivot into its network, so it is opt-in (RFC 023 §9.3).
|
|
30
|
+
*/
|
|
31
|
+
allowNonLoopback?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Forward a whole tailnet port to one local backend. */
|
|
34
|
+
export interface ServeTargetConfig extends ServeOptions {
|
|
35
|
+
/** Tailnet port to listen on (e.g. 443). */
|
|
36
|
+
port: number;
|
|
37
|
+
/** Backend URL, e.g. `http://localhost:3000`. Must be http(s). */
|
|
38
|
+
target: string;
|
|
39
|
+
}
|
|
40
|
+
/** Serve a static directory (single-page-app shape). */
|
|
41
|
+
export interface ServeStaticConfig extends ServeOptions {
|
|
42
|
+
/** Tailnet port to listen on. */
|
|
43
|
+
port: number;
|
|
44
|
+
/** Directory to serve; resolved to an absolute path. */
|
|
45
|
+
dir: string;
|
|
46
|
+
/** Rewrite static misses to this path (SPA fallback), e.g. `/index.html`. */
|
|
47
|
+
fallback?: string;
|
|
48
|
+
}
|
|
49
|
+
/** One entry of a {@link ServeRoutesConfig} `routes` map. */
|
|
50
|
+
export interface ServeRouteValue {
|
|
51
|
+
/** Backend URL for a proxy route. Mutually exclusive with {@link dir}. */
|
|
52
|
+
target?: string;
|
|
53
|
+
/** Directory for a static route. Mutually exclusive with {@link target}. */
|
|
54
|
+
dir?: string;
|
|
55
|
+
/** SPA fallback path; only meaningful with {@link dir}. */
|
|
56
|
+
fallback?: string;
|
|
57
|
+
/** Strip the matched prefix before proxying; only meaningful with {@link target} (default false). */
|
|
58
|
+
stripPrefix?: boolean;
|
|
59
|
+
/** Per-route loginName globs; overrides the config-level {@link ServeOptions.allow}. */
|
|
60
|
+
allow?: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Mixed path routes. Keys are path prefixes matched by longest prefix
|
|
64
|
+
* (order-independent); values are a backend URL string, or a
|
|
65
|
+
* {@link ServeRouteValue} for static/stripPrefix/allow control.
|
|
66
|
+
*/
|
|
67
|
+
export interface ServeRoutesConfig extends ServeOptions {
|
|
68
|
+
/** Tailnet port to listen on. */
|
|
69
|
+
port: number;
|
|
70
|
+
/** Prefix → backend URL string or {@link ServeRouteValue}. */
|
|
71
|
+
routes: Record<string, string | ServeRouteValue>;
|
|
72
|
+
}
|
|
73
|
+
/** The union accepted by {@link TruffleServe}. */
|
|
74
|
+
export type ServeConfig = ServeTargetConfig | ServeStaticConfig | ServeRoutesConfig;
|
|
75
|
+
/** Runtime error surfaced on a {@link ServeHandle} (G5 fix, RFC 023 §7). */
|
|
76
|
+
export interface ServeErrorInfo {
|
|
77
|
+
/** Sidecar error code, e.g. `SERVE_ERROR`, `CONNECTION_REFUSED`. */
|
|
78
|
+
code: string;
|
|
79
|
+
/** Human-readable detail. */
|
|
80
|
+
message: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A running serve, 1:1 with a proxy `id`. An `EventEmitter` for runtime
|
|
84
|
+
* errors:
|
|
85
|
+
*
|
|
86
|
+
* - `'serveError'` — `(info: ServeErrorInfo)`. Always emitted; safe to leave
|
|
87
|
+
* unlistened. Prefer this for programmatic handling.
|
|
88
|
+
* - `'error'` — `(info: ServeErrorInfo)`. Emitted **only when a listener is
|
|
89
|
+
* attached** (an unlistened EventEmitter `'error'` throws and would crash
|
|
90
|
+
* the process). Same payload as `'serveError'`.
|
|
91
|
+
* - `'close'` — the proxy stopped (via {@link close} or a sidecar-side stop).
|
|
92
|
+
* Fires once.
|
|
93
|
+
*/
|
|
94
|
+
export declare class ServeHandle extends EventEmitter {
|
|
95
|
+
#private;
|
|
96
|
+
/** The proxy id backing this serve. */
|
|
97
|
+
readonly id: string;
|
|
98
|
+
/**
|
|
99
|
+
* The normalized, frozen config that created this handle — every default
|
|
100
|
+
* filled and every `dir` resolved to an absolute path. Persist it and
|
|
101
|
+
* replay `mesh.serve(handle.config)` to recreate an identical serve
|
|
102
|
+
* (RFC 023 D16); the library never persists on its own.
|
|
103
|
+
*/
|
|
104
|
+
readonly config: ServeConfig;
|
|
105
|
+
/** @internal Constructed by {@link createServeNamespace}. */
|
|
106
|
+
constructor(id: string, config: ServeConfig, proxy: NapiProxy, retire: () => void);
|
|
107
|
+
/** Public serving URL from the `add()` result (`https://name.tailnet.ts.net[:port]`). */
|
|
108
|
+
get url(): string;
|
|
109
|
+
/** Tailnet port the serve is listening on (resolved from the `add()` result). */
|
|
110
|
+
get port(): number;
|
|
111
|
+
/** @internal Fill url/port from the `NapiProxyInfo` once `add()` resolves. */
|
|
112
|
+
_start(url: string, port: number): void;
|
|
113
|
+
/** @internal Route a `'error'` proxy event to this handle. */
|
|
114
|
+
_onError(code: string | undefined, message: string | undefined): void;
|
|
115
|
+
/** @internal Route a `'stopped'` proxy event to this handle. */
|
|
116
|
+
_onStopped(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Stop serving and release the tailnet port (`proxy.remove(id)`). Emits
|
|
119
|
+
* `'close'` once. Idempotent.
|
|
120
|
+
*/
|
|
121
|
+
close(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The `mesh.serve` verb: publish a local service or directory to the tailnet.
|
|
125
|
+
* Resolves with a {@link ServeHandle} once the proxy is running.
|
|
126
|
+
*/
|
|
127
|
+
export type TruffleServe = (config: ServeConfig) => Promise<ServeHandle>;
|
|
128
|
+
/**
|
|
129
|
+
* Normalize any {@link ServeConfig} shape into the single `NapiProxyConfig`
|
|
130
|
+
* the proxy engine consumes. Pure and deterministic; exported so the shape
|
|
131
|
+
* can be asserted directly. Throws on a `funnel` key (reserved), a malformed
|
|
132
|
+
* shape, or a non-http(s) `target`.
|
|
133
|
+
*/
|
|
134
|
+
export declare function normalizeServeConfig(config: ServeConfig): NapiProxyConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Build the `mesh.serve` verb over a lazy proxy getter. `getProxy` is called
|
|
137
|
+
* per serve (NapiProxy handles are per-call); proxy events are node-global,
|
|
138
|
+
* so one `onEvent` subscription — installed on the first serve — routes
|
|
139
|
+
* runtime errors and stops to every live handle by id.
|
|
140
|
+
*/
|
|
141
|
+
export declare function createServeNamespace(getProxy: () => NapiProxy): TruffleServe;
|
|
142
|
+
//# sourceMappingURL=serve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EAGhB,MAAM,0BAA0B,CAAC;AAElC,yDAAyD;AACzD,MAAM,WAA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)` is the one ergonomic verb for publishing a local
|
|
4
|
+
// service or a static directory to the whole tailnet, mirroring the
|
|
5
|
+
// `tailscale serve` mental model. It is sugar over the shipped proxy engine
|
|
6
|
+
// (`mesh.proxy()` / Rust `Node::proxy()`): a serve handle maps 1:1 to a proxy
|
|
7
|
+
// `id`, and every config shape below normalizes to one `NapiProxyConfig`.
|
|
8
|
+
//
|
|
9
|
+
// The docs rule (RFC 023 §5, D2): you wrote the request handler →
|
|
10
|
+
// `mesh.http.createServer`; it's a directory or another process → `serve`.
|
|
11
|
+
//
|
|
12
|
+
// Three config shapes, one function:
|
|
13
|
+
// • { port, target } — forward a whole port to a backend
|
|
14
|
+
// • { port, dir, fallback? } — serve a static directory (SPA)
|
|
15
|
+
// • { port, routes } — mixed path routes (SPA + APIs)
|
|
16
|
+
//
|
|
17
|
+
// TLS defaults ON here (unlike `createServer`): the audience is browsers, and
|
|
18
|
+
// this preserves the shipped engine's always-TLS behavior (RFC 023 D5).
|
|
19
|
+
import { EventEmitter } from 'node:events';
|
|
20
|
+
import { resolve as resolvePath } from 'node:path';
|
|
21
|
+
/**
|
|
22
|
+
* A running serve, 1:1 with a proxy `id`. An `EventEmitter` for runtime
|
|
23
|
+
* errors:
|
|
24
|
+
*
|
|
25
|
+
* - `'serveError'` — `(info: ServeErrorInfo)`. Always emitted; safe to leave
|
|
26
|
+
* unlistened. Prefer this for programmatic handling.
|
|
27
|
+
* - `'error'` — `(info: ServeErrorInfo)`. Emitted **only when a listener is
|
|
28
|
+
* attached** (an unlistened EventEmitter `'error'` throws and would crash
|
|
29
|
+
* the process). Same payload as `'serveError'`.
|
|
30
|
+
* - `'close'` — the proxy stopped (via {@link close} or a sidecar-side stop).
|
|
31
|
+
* Fires once.
|
|
32
|
+
*/
|
|
33
|
+
export class ServeHandle extends EventEmitter {
|
|
34
|
+
/** The proxy id backing this serve. */
|
|
35
|
+
id;
|
|
36
|
+
/**
|
|
37
|
+
* The normalized, frozen config that created this handle — every default
|
|
38
|
+
* filled and every `dir` resolved to an absolute path. Persist it and
|
|
39
|
+
* replay `mesh.serve(handle.config)` to recreate an identical serve
|
|
40
|
+
* (RFC 023 D16); the library never persists on its own.
|
|
41
|
+
*/
|
|
42
|
+
config;
|
|
43
|
+
#url = '';
|
|
44
|
+
#port = 0;
|
|
45
|
+
#proxy;
|
|
46
|
+
#retire;
|
|
47
|
+
#closed = false;
|
|
48
|
+
#closeEmitted = false;
|
|
49
|
+
/** @internal Constructed by {@link createServeNamespace}. */
|
|
50
|
+
constructor(id, config, proxy, retire) {
|
|
51
|
+
super();
|
|
52
|
+
this.id = id;
|
|
53
|
+
this.config = config;
|
|
54
|
+
this.#proxy = proxy;
|
|
55
|
+
this.#retire = retire;
|
|
56
|
+
}
|
|
57
|
+
/** Public serving URL from the `add()` result (`https://name.tailnet.ts.net[:port]`). */
|
|
58
|
+
get url() {
|
|
59
|
+
return this.#url;
|
|
60
|
+
}
|
|
61
|
+
/** Tailnet port the serve is listening on (resolved from the `add()` result). */
|
|
62
|
+
get port() {
|
|
63
|
+
return this.#port;
|
|
64
|
+
}
|
|
65
|
+
/** @internal Fill url/port from the `NapiProxyInfo` once `add()` resolves. */
|
|
66
|
+
_start(url, port) {
|
|
67
|
+
this.#url = url;
|
|
68
|
+
this.#port = port;
|
|
69
|
+
}
|
|
70
|
+
/** @internal Route a `'error'` proxy event to this handle. */
|
|
71
|
+
_onError(code, message) {
|
|
72
|
+
const info = { code: code ?? '', message: message ?? '' };
|
|
73
|
+
// 'serveError' never crashes an unlistened emitter; mirror onto the
|
|
74
|
+
// conventional 'error' only when someone is listening.
|
|
75
|
+
this.emit('serveError', info);
|
|
76
|
+
if (this.listenerCount('error') > 0)
|
|
77
|
+
this.emit('error', info);
|
|
78
|
+
}
|
|
79
|
+
/** @internal Route a `'stopped'` proxy event to this handle. */
|
|
80
|
+
_onStopped() {
|
|
81
|
+
if (this.#closed)
|
|
82
|
+
return;
|
|
83
|
+
this.#closed = true;
|
|
84
|
+
this.#retire();
|
|
85
|
+
this.#emitClose();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Stop serving and release the tailnet port (`proxy.remove(id)`). Emits
|
|
89
|
+
* `'close'` once. Idempotent.
|
|
90
|
+
*/
|
|
91
|
+
async close() {
|
|
92
|
+
if (this.#closed)
|
|
93
|
+
return;
|
|
94
|
+
this.#closed = true;
|
|
95
|
+
this.#retire();
|
|
96
|
+
try {
|
|
97
|
+
await this.#proxy.remove(this.id);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
this.#emitClose();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
#emitClose() {
|
|
104
|
+
if (this.#closeEmitted)
|
|
105
|
+
return;
|
|
106
|
+
this.#closeEmitted = true;
|
|
107
|
+
this.emit('close');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Normalize any {@link ServeConfig} shape into the single `NapiProxyConfig`
|
|
112
|
+
* the proxy engine consumes. Pure and deterministic; exported so the shape
|
|
113
|
+
* can be asserted directly. Throws on a `funnel` key (reserved), a malformed
|
|
114
|
+
* shape, or a non-http(s) `target`.
|
|
115
|
+
*/
|
|
116
|
+
export function normalizeServeConfig(config) {
|
|
117
|
+
return canonicalToNapi(canonicalServeConfig(config));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Build the `mesh.serve` verb over a lazy proxy getter. `getProxy` is called
|
|
121
|
+
* per serve (NapiProxy handles are per-call); proxy events are node-global,
|
|
122
|
+
* so one `onEvent` subscription — installed on the first serve — routes
|
|
123
|
+
* runtime errors and stops to every live handle by id.
|
|
124
|
+
*/
|
|
125
|
+
export function createServeNamespace(getProxy) {
|
|
126
|
+
const handles = new Map();
|
|
127
|
+
let eventProxy = null;
|
|
128
|
+
function routeEvent(ev) {
|
|
129
|
+
const handle = handles.get(ev.id);
|
|
130
|
+
if (!handle)
|
|
131
|
+
return;
|
|
132
|
+
if (ev.eventType === 'error') {
|
|
133
|
+
handle._onError(ev.code, ev.message);
|
|
134
|
+
}
|
|
135
|
+
else if (ev.eventType === 'stopped') {
|
|
136
|
+
handle._onStopped();
|
|
137
|
+
}
|
|
138
|
+
// 'started' carries url/listenPort, but the add() result already gives us
|
|
139
|
+
// those synchronously — nothing to route.
|
|
140
|
+
}
|
|
141
|
+
function ensureSubscribed(proxy) {
|
|
142
|
+
if (eventProxy)
|
|
143
|
+
return;
|
|
144
|
+
// Retain the subscribed handle so the native subscription outlives GC of
|
|
145
|
+
// this NapiProxy. Events are node-global (all handles share one Arc<Node>).
|
|
146
|
+
eventProxy = proxy;
|
|
147
|
+
proxy.onEvent(routeEvent);
|
|
148
|
+
}
|
|
149
|
+
return async function serve(config) {
|
|
150
|
+
const canonical = canonicalServeConfig(config); // throws: funnel / bad shape
|
|
151
|
+
const napiConfig = canonicalToNapi(canonical); // throws: non-http(s) target
|
|
152
|
+
const replayConfig = deepFreeze(canonical);
|
|
153
|
+
const id = napiConfig.id;
|
|
154
|
+
if (handles.has(id)) {
|
|
155
|
+
throw new Error(`serve: id ${JSON.stringify(id)} is already serving on this node — ` +
|
|
156
|
+
'pass a distinct `id` (the default is `serve-${port}`, so two serves ' +
|
|
157
|
+
'on the same port collide).');
|
|
158
|
+
}
|
|
159
|
+
const proxy = getProxy();
|
|
160
|
+
// Subscribe and register the handle before add() resolves, so a runtime
|
|
161
|
+
// error emitted the instant the listener starts is routed, not dropped.
|
|
162
|
+
ensureSubscribed(proxy);
|
|
163
|
+
const handle = new ServeHandle(id, replayConfig, proxy, () => {
|
|
164
|
+
if (handles.get(id) === handle)
|
|
165
|
+
handles.delete(id);
|
|
166
|
+
});
|
|
167
|
+
handles.set(id, handle);
|
|
168
|
+
try {
|
|
169
|
+
const info = await proxy.add(napiConfig);
|
|
170
|
+
handle._start(info.url, info.listenPort);
|
|
171
|
+
return handle;
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
if (handles.get(id) === handle)
|
|
175
|
+
handles.delete(id);
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// ─── normalization ────────────────────────────────────────────────────────
|
|
181
|
+
/**
|
|
182
|
+
* Fill defaults, resolve dirs to absolute, and validate — producing a
|
|
183
|
+
* canonical {@link ServeConfig} that is its own replayable form. Idempotent:
|
|
184
|
+
* `canonicalServeConfig(canonicalServeConfig(x))` normalizes identically, so
|
|
185
|
+
* replaying `handle.config` reproduces the original `NapiProxyConfig`.
|
|
186
|
+
*/
|
|
187
|
+
function canonicalServeConfig(config) {
|
|
188
|
+
if (!config || typeof config !== 'object') {
|
|
189
|
+
throw new TypeError('serve: config must be an object');
|
|
190
|
+
}
|
|
191
|
+
const c = config;
|
|
192
|
+
if (c.funnel !== undefined) {
|
|
193
|
+
throw new Error('funnel is not supported yet — RFC 023 §9.6 reserves it for a future phase');
|
|
194
|
+
}
|
|
195
|
+
if (!Number.isInteger(c.port) || c.port < 0 || c.port > 65535) {
|
|
196
|
+
throw new TypeError(`serve: invalid port ${String(c.port)} (expected an integer 0–65535)`);
|
|
197
|
+
}
|
|
198
|
+
const shapes = Number(c.target !== undefined) + Number(c.dir !== undefined) + Number(c.routes !== undefined);
|
|
199
|
+
if (shapes !== 1) {
|
|
200
|
+
throw new TypeError(`serve: config must have exactly one of \`target\`, \`dir\`, or \`routes\` (got ${shapes === 0 ? 'none' : 'several'})`);
|
|
201
|
+
}
|
|
202
|
+
const id = c.id ?? `serve-${c.port}`;
|
|
203
|
+
const common = {
|
|
204
|
+
port: c.port,
|
|
205
|
+
id,
|
|
206
|
+
name: c.name ?? id,
|
|
207
|
+
tls: c.tls ?? true,
|
|
208
|
+
};
|
|
209
|
+
if (c.allow !== undefined)
|
|
210
|
+
common.allow = [...c.allow];
|
|
211
|
+
if (c.allowNonLoopback !== undefined)
|
|
212
|
+
common.allowNonLoopback = c.allowNonLoopback;
|
|
213
|
+
if (c.target !== undefined) {
|
|
214
|
+
return { ...common, target: c.target };
|
|
215
|
+
}
|
|
216
|
+
if (c.dir !== undefined) {
|
|
217
|
+
const out = { ...common, dir: resolvePath(c.dir) };
|
|
218
|
+
if (c.fallback !== undefined)
|
|
219
|
+
out.fallback = c.fallback;
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
const routesIn = c.routes;
|
|
223
|
+
if (Object.keys(routesIn).length === 0) {
|
|
224
|
+
throw new TypeError('serve: `routes` must have at least one entry');
|
|
225
|
+
}
|
|
226
|
+
const routes = {};
|
|
227
|
+
for (const [prefix, value] of Object.entries(routesIn)) {
|
|
228
|
+
routes[prefix] = canonicalRouteValue(value);
|
|
229
|
+
}
|
|
230
|
+
return { ...common, routes };
|
|
231
|
+
}
|
|
232
|
+
/** Canonicalize one route value: string stays a URL; object resolves its dir. */
|
|
233
|
+
function canonicalRouteValue(value) {
|
|
234
|
+
if (typeof value === 'string')
|
|
235
|
+
return value;
|
|
236
|
+
if (!value || typeof value !== 'object') {
|
|
237
|
+
throw new TypeError('serve: a route value must be a URL string or a route object');
|
|
238
|
+
}
|
|
239
|
+
const hasTarget = value.target !== undefined;
|
|
240
|
+
const hasDir = value.dir !== undefined;
|
|
241
|
+
if (hasTarget === hasDir) {
|
|
242
|
+
throw new TypeError('serve: each route object needs exactly one of `target` or `dir`');
|
|
243
|
+
}
|
|
244
|
+
const out = {};
|
|
245
|
+
if (hasTarget) {
|
|
246
|
+
out.target = value.target;
|
|
247
|
+
if (value.stripPrefix !== undefined)
|
|
248
|
+
out.stripPrefix = value.stripPrefix;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
out.dir = resolvePath(value.dir);
|
|
252
|
+
if (value.fallback !== undefined)
|
|
253
|
+
out.fallback = value.fallback;
|
|
254
|
+
}
|
|
255
|
+
if (value.allow !== undefined)
|
|
256
|
+
out.allow = [...value.allow];
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
/** Convert a canonical config (defaults filled, dirs absolute) to NAPI shape. */
|
|
260
|
+
function canonicalToNapi(config) {
|
|
261
|
+
const c = config;
|
|
262
|
+
const napi = {
|
|
263
|
+
id: c.id,
|
|
264
|
+
name: c.name,
|
|
265
|
+
listenPort: c.port,
|
|
266
|
+
// Ignored when `routes` is present; the NAPI field is required (RFC 023).
|
|
267
|
+
targetPort: 0,
|
|
268
|
+
tls: c.tls,
|
|
269
|
+
};
|
|
270
|
+
if (c.allow !== undefined)
|
|
271
|
+
napi.allow = [...c.allow];
|
|
272
|
+
if (c.allowNonLoopback !== undefined)
|
|
273
|
+
napi.allowNonLoopback = c.allowNonLoopback;
|
|
274
|
+
if (c.target !== undefined) {
|
|
275
|
+
const { host, port, scheme } = parseTargetUrl(c.target);
|
|
276
|
+
napi.targetHost = host;
|
|
277
|
+
napi.targetPort = port;
|
|
278
|
+
napi.targetScheme = scheme;
|
|
279
|
+
return napi;
|
|
280
|
+
}
|
|
281
|
+
const routes = [];
|
|
282
|
+
if (c.dir !== undefined) {
|
|
283
|
+
const route = { prefix: '/', dir: c.dir };
|
|
284
|
+
if (c.fallback !== undefined)
|
|
285
|
+
route.fallback = c.fallback;
|
|
286
|
+
routes.push(route);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
for (const [prefix, value] of Object.entries(c.routes)) {
|
|
290
|
+
routes.push(routeValueToNapi(prefix, value));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
napi.routes = routes;
|
|
294
|
+
return napi;
|
|
295
|
+
}
|
|
296
|
+
/** Convert a canonical route value to a `NapiProxyRoute`. */
|
|
297
|
+
function routeValueToNapi(prefix, value) {
|
|
298
|
+
const route = { prefix };
|
|
299
|
+
if (typeof value === 'string') {
|
|
300
|
+
route.targetUrl = value;
|
|
301
|
+
return route;
|
|
302
|
+
}
|
|
303
|
+
if (value.target !== undefined) {
|
|
304
|
+
route.targetUrl = value.target;
|
|
305
|
+
if (value.stripPrefix !== undefined)
|
|
306
|
+
route.stripPrefix = value.stripPrefix;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
route.dir = value.dir;
|
|
310
|
+
if (value.fallback !== undefined)
|
|
311
|
+
route.fallback = value.fallback;
|
|
312
|
+
}
|
|
313
|
+
if (value.allow !== undefined)
|
|
314
|
+
route.allow = [...value.allow];
|
|
315
|
+
return route;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Parse an http(s) target URL into host/port/scheme. A bare `host:port`
|
|
319
|
+
* (no scheme) is rejected: WHATWG URL reads `localhost` as a scheme, so it
|
|
320
|
+
* fails the http(s) check with a pointer to add `http://`.
|
|
321
|
+
*/
|
|
322
|
+
function parseTargetUrl(target) {
|
|
323
|
+
let url;
|
|
324
|
+
try {
|
|
325
|
+
url = new URL(target);
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
throw new TypeError(`serve: invalid target URL ${JSON.stringify(target)} — pass a full http(s) URL, e.g. "http://localhost:3000"`);
|
|
329
|
+
}
|
|
330
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
331
|
+
throw new TypeError(`serve: target must be an http:// or https:// URL, got ${JSON.stringify(target)} ` +
|
|
332
|
+
'(a bare "host:port" is read as a URL scheme — include http://)');
|
|
333
|
+
}
|
|
334
|
+
const scheme = url.protocol.slice(0, -1);
|
|
335
|
+
const port = url.port ? Number(url.port) : scheme === 'https' ? 443 : 80;
|
|
336
|
+
return { host: url.hostname, port, scheme };
|
|
337
|
+
}
|
|
338
|
+
/** Recursively freeze an object graph (config + nested routes/arrays). */
|
|
339
|
+
function deepFreeze(value) {
|
|
340
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
341
|
+
for (const child of Object.values(value))
|
|
342
|
+
deepFreeze(child);
|
|
343
|
+
Object.freeze(value);
|
|
344
|
+
}
|
|
345
|
+
return value;
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=serve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":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