nstantpage-agent 0.8.14 → 0.8.16
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/commands/start.js +6 -1
- package/dist/localServer.d.ts +3 -0
- package/dist/localServer.js +18 -0
- package/dist/tunnel.d.ts +6 -0
- package/dist/tunnel.js +22 -6
- package/package.json +1 -1
package/dist/commands/start.js
CHANGED
|
@@ -776,7 +776,7 @@ async function startAdditionalProject(projectId, opts) {
|
|
|
776
776
|
if (databaseUrl)
|
|
777
777
|
serverEnv['DATABASE_URL'] = databaseUrl;
|
|
778
778
|
// Note: tunnel is created after localServer but before start(),
|
|
779
|
-
// so the onSyncDirty
|
|
779
|
+
// so the onSyncDirty/onSetDevPort callbacks capture it via closure (late-binding).
|
|
780
780
|
let tunnel;
|
|
781
781
|
const localServer = new LocalServer({
|
|
782
782
|
projectDir, projectId,
|
|
@@ -788,6 +788,11 @@ async function startAdditionalProject(projectId, opts) {
|
|
|
788
788
|
tunnel.sendSyncDirty(pid);
|
|
789
789
|
}
|
|
790
790
|
},
|
|
791
|
+
onSetDevPort: (port) => {
|
|
792
|
+
if (tunnel) {
|
|
793
|
+
tunnel.setDevPort(port);
|
|
794
|
+
}
|
|
795
|
+
},
|
|
791
796
|
});
|
|
792
797
|
tunnel = new TunnelClient({
|
|
793
798
|
gatewayUrl: opts.gatewayUrl,
|
package/dist/localServer.d.ts
CHANGED
|
@@ -62,6 +62,8 @@ export interface LocalServerOptions {
|
|
|
62
62
|
backendUrl?: string;
|
|
63
63
|
/** Called when file watcher detects changes — should send sync-dirty via tunnel */
|
|
64
64
|
onSyncDirty?: (projectId: string) => void;
|
|
65
|
+
/** Called when dev port is updated via /live/set-dev-port */
|
|
66
|
+
onSetDevPort?: (port: number) => void;
|
|
65
67
|
}
|
|
66
68
|
export declare class LocalServer {
|
|
67
69
|
private server;
|
|
@@ -127,6 +129,7 @@ export declare class LocalServer {
|
|
|
127
129
|
private handleTree;
|
|
128
130
|
private handleFileContent;
|
|
129
131
|
private handleSaveFile;
|
|
132
|
+
private handleSetDevPort;
|
|
130
133
|
private handleHealth;
|
|
131
134
|
/**
|
|
132
135
|
* Get a pg Pool connected to this project's local database.
|
package/dist/localServer.js
CHANGED
|
@@ -404,6 +404,7 @@ export class LocalServer {
|
|
|
404
404
|
'/live/tree': this.handleTree,
|
|
405
405
|
'/live/file-content': this.handleFileContent,
|
|
406
406
|
'/live/save-file': this.handleSaveFile,
|
|
407
|
+
'/live/set-dev-port': this.handleSetDevPort,
|
|
407
408
|
'/health': this.handleHealth,
|
|
408
409
|
};
|
|
409
410
|
if (handlers[path])
|
|
@@ -1225,6 +1226,23 @@ export class LocalServer {
|
|
|
1225
1226
|
this.json(res, { error: error.message }, 500);
|
|
1226
1227
|
}
|
|
1227
1228
|
}
|
|
1229
|
+
// ─── /live/set-dev-port ─────────────────────────────────────
|
|
1230
|
+
async handleSetDevPort(_req, res, body) {
|
|
1231
|
+
try {
|
|
1232
|
+
const { port } = JSON.parse(body);
|
|
1233
|
+
if (!port || typeof port !== 'number' || port < 1 || port > 65535) {
|
|
1234
|
+
this.json(res, { error: 'Invalid port number' }, 400);
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
if (this.options.onSetDevPort) {
|
|
1238
|
+
this.options.onSetDevPort(port);
|
|
1239
|
+
}
|
|
1240
|
+
this.json(res, { success: true, port });
|
|
1241
|
+
}
|
|
1242
|
+
catch (error) {
|
|
1243
|
+
this.json(res, { error: error.message }, 500);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1228
1246
|
// ─── /health ─────────────────────────────────────────────────
|
|
1229
1247
|
async handleHealth(_req, res) {
|
|
1230
1248
|
this.json(res, {
|
package/dist/tunnel.d.ts
CHANGED
|
@@ -48,7 +48,13 @@ export declare class TunnelClient {
|
|
|
48
48
|
private wsChannels;
|
|
49
49
|
/** Listeners for status changes (used by tray app) */
|
|
50
50
|
private statusListeners;
|
|
51
|
+
/** Override dev port (set dynamically for LocalRepo when user starts dev server) */
|
|
52
|
+
private _devPortOverride;
|
|
51
53
|
constructor(options: TunnelClientOptions);
|
|
54
|
+
/** Get the effective dev server port (override or default) */
|
|
55
|
+
get devPort(): number;
|
|
56
|
+
/** Dynamically set dev port (e.g., when user starts dev server on a specific port) */
|
|
57
|
+
setDevPort(port: number): void;
|
|
52
58
|
/**
|
|
53
59
|
* Handle OS sleep/wake events.
|
|
54
60
|
* When the machine wakes from sleep (or screen unlock), immediately attempt
|
package/dist/tunnel.js
CHANGED
|
@@ -38,10 +38,21 @@ export class TunnelClient {
|
|
|
38
38
|
wsChannels = new Map();
|
|
39
39
|
/** Listeners for status changes (used by tray app) */
|
|
40
40
|
statusListeners = new Set();
|
|
41
|
+
/** Override dev port (set dynamically for LocalRepo when user starts dev server) */
|
|
42
|
+
_devPortOverride = null;
|
|
41
43
|
constructor(options) {
|
|
42
44
|
this.options = options;
|
|
43
45
|
this.setupSleepWakeHandlers();
|
|
44
46
|
}
|
|
47
|
+
/** Get the effective dev server port (override or default) */
|
|
48
|
+
get devPort() {
|
|
49
|
+
return this._devPortOverride ?? this.options.devPort;
|
|
50
|
+
}
|
|
51
|
+
/** Dynamically set dev port (e.g., when user starts dev server on a specific port) */
|
|
52
|
+
setDevPort(port) {
|
|
53
|
+
console.log(` [Tunnel] Dev port set to ${port} (was ${this._devPortOverride ?? this.options.devPort})`);
|
|
54
|
+
this._devPortOverride = port;
|
|
55
|
+
}
|
|
45
56
|
/**
|
|
46
57
|
* Handle OS sleep/wake events.
|
|
47
58
|
* When the machine wakes from sleep (or screen unlock), immediately attempt
|
|
@@ -349,9 +360,9 @@ export class TunnelClient {
|
|
|
349
360
|
* Vite dev server and relay data bidirectionally through the tunnel.
|
|
350
361
|
* This enables Vite HMR to work through the cloud preview URL.
|
|
351
362
|
*/
|
|
352
|
-
handleWsOpenDevServer(wsId, url, protocol) {
|
|
353
|
-
const
|
|
354
|
-
const wsUrl = `ws://127.0.0.1:${
|
|
363
|
+
handleWsOpenDevServer(wsId, url, protocol, targetPort) {
|
|
364
|
+
const port = (targetPort && targetPort > 0) ? targetPort : this.devPort;
|
|
365
|
+
const wsUrl = `ws://127.0.0.1:${port}${url}`;
|
|
355
366
|
console.log(` [Tunnel] Opening HMR WS relay: ${wsId} → ${wsUrl}`);
|
|
356
367
|
const wsOptions = {};
|
|
357
368
|
const protocols = protocol ? protocol.split(',').map(p => p.trim()) : undefined;
|
|
@@ -461,7 +472,7 @@ export class TunnelClient {
|
|
|
461
472
|
break;
|
|
462
473
|
case 'ws-open':
|
|
463
474
|
if (msg.target === 'dev-server') {
|
|
464
|
-
this.handleWsOpenDevServer(msg.wsId, msg.url || '/', msg.protocol);
|
|
475
|
+
this.handleWsOpenDevServer(msg.wsId, msg.url || '/', msg.protocol, msg.targetPort);
|
|
465
476
|
}
|
|
466
477
|
else {
|
|
467
478
|
this.handleWsOpen(msg.wsId, msg.sessionId, msg.projectId);
|
|
@@ -491,9 +502,14 @@ export class TunnelClient {
|
|
|
491
502
|
* - Everything else → Dev server (Vite HMR, page loads, etc.)
|
|
492
503
|
*/
|
|
493
504
|
handleHttpRequest(request) {
|
|
494
|
-
const { url } = request;
|
|
505
|
+
const { url, headers } = request;
|
|
495
506
|
const isApiRequest = url.startsWith('/live/') || url === '/health';
|
|
496
|
-
|
|
507
|
+
// Use x-target-port header if present (multi-port tunneling), else fall back to default
|
|
508
|
+
const portHeader = headers?.['x-target-port'];
|
|
509
|
+
const overridePort = portHeader ? parseInt(String(portHeader), 10) : NaN;
|
|
510
|
+
const targetPort = isApiRequest
|
|
511
|
+
? this.options.apiPort
|
|
512
|
+
: (overridePort > 0 ? overridePort : this.devPort);
|
|
497
513
|
this.forwardToLocal(request, targetPort);
|
|
498
514
|
this.requestsForwarded++;
|
|
499
515
|
}
|
package/package.json
CHANGED