fluxy-bot 0.1.44 → 0.1.46
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/package.json +1 -1
- package/supervisor/index.ts +4 -1
- package/supervisor/vite-dev.ts +21 -19
package/package.json
CHANGED
package/supervisor/index.ts
CHANGED
|
@@ -78,8 +78,11 @@ export async function startSupervisor() {
|
|
|
78
78
|
// Frontend requests → Vite dev server (fallback to worker if Vite is down)
|
|
79
79
|
const targetPort = isViteAlive() ? vitePort : workerPort;
|
|
80
80
|
|
|
81
|
+
// Override Host header to localhost so Vite accepts the request
|
|
82
|
+
const headers = { ...req.headers, host: `127.0.0.1:${targetPort}` };
|
|
83
|
+
|
|
81
84
|
const proxy = http.request(
|
|
82
|
-
{ host: '127.0.0.1', port: targetPort, path: req.url, method: req.method, headers
|
|
85
|
+
{ host: '127.0.0.1', port: targetPort, path: req.url, method: req.method, headers },
|
|
83
86
|
(proxyRes) => {
|
|
84
87
|
res.writeHead(proxyRes.statusCode!, proxyRes.headers);
|
|
85
88
|
proxyRes.pipe(res);
|
package/supervisor/vite-dev.ts
CHANGED
|
@@ -13,33 +13,41 @@ export function getVitePort(basePort: number): number {
|
|
|
13
13
|
|
|
14
14
|
export function spawnVite(port: number): Promise<void> {
|
|
15
15
|
return new Promise((resolve) => {
|
|
16
|
-
const
|
|
17
|
-
child = spawn(
|
|
16
|
+
const viteCli = path.join(PKG_DIR, 'node_modules', 'vite', 'bin', 'vite.js');
|
|
17
|
+
child = spawn(process.execPath, [viteCli, '--port', String(port), '--strictPort'], {
|
|
18
18
|
cwd: PKG_DIR,
|
|
19
19
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
20
20
|
env: { ...process.env },
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
let resolved = false;
|
|
24
|
+
const onReady = () => {
|
|
25
|
+
if (!resolved) { resolved = true; resolve(); }
|
|
26
|
+
};
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
const checkOutput = (d: Buffer) => {
|
|
26
29
|
const text = d.toString();
|
|
27
30
|
process.stdout.write(d);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
resolved = true;
|
|
32
|
-
resolve();
|
|
31
|
+
// Vite prints "Local:" when ready (may appear on stdout or stderr depending on version)
|
|
32
|
+
if (text.includes('Local:') || text.includes('ready in')) {
|
|
33
|
+
onReady();
|
|
33
34
|
}
|
|
34
|
-
}
|
|
35
|
+
};
|
|
35
36
|
|
|
36
|
-
child.
|
|
37
|
-
|
|
37
|
+
child.stdout?.on('data', checkOutput);
|
|
38
|
+
child.stderr?.on('data', checkOutput);
|
|
39
|
+
|
|
40
|
+
child.on('error', (err) => {
|
|
41
|
+
log.error(`Vite spawn error: ${err.message}`);
|
|
42
|
+
child = null;
|
|
43
|
+
onReady(); // don't block supervisor startup
|
|
38
44
|
});
|
|
39
45
|
|
|
40
46
|
child.on('exit', (code) => {
|
|
41
47
|
if (code !== 0 && code !== null) {
|
|
42
48
|
log.warn(`Vite dev server crashed (code ${code})`);
|
|
49
|
+
child = null;
|
|
50
|
+
onReady(); // don't block if it crashes during startup
|
|
43
51
|
if (restarts < MAX_RESTARTS) {
|
|
44
52
|
restarts++;
|
|
45
53
|
log.info(`Restarting Vite (${restarts}/${MAX_RESTARTS})...`);
|
|
@@ -50,14 +58,8 @@ export function spawnVite(port: number): Promise<void> {
|
|
|
50
58
|
}
|
|
51
59
|
});
|
|
52
60
|
|
|
53
|
-
// If Vite doesn't
|
|
54
|
-
setTimeout(
|
|
55
|
-
if (!resolved) {
|
|
56
|
-
resolved = true;
|
|
57
|
-
log.warn('Vite startup timed out — resolving anyway');
|
|
58
|
-
resolve();
|
|
59
|
-
}
|
|
60
|
-
}, 15_000);
|
|
61
|
+
// If Vite doesn't signal ready within 15s, resolve anyway
|
|
62
|
+
setTimeout(onReady, 15_000);
|
|
61
63
|
|
|
62
64
|
log.ok(`Vite dev server spawned on port ${port}`);
|
|
63
65
|
});
|