fluxy-bot 0.1.5 → 0.1.6
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/cli.js +33 -5
- package/package.json +1 -1
- package/supervisor/index.ts +9 -0
- package/supervisor/tunnel.ts +1 -0
package/bin/cli.js
CHANGED
|
@@ -193,7 +193,7 @@ async function installCloudflared() {
|
|
|
193
193
|
// ── Boot server ──
|
|
194
194
|
|
|
195
195
|
function bootServer() {
|
|
196
|
-
return new Promise((resolve) => {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
197
|
const child = spawn(
|
|
198
198
|
process.execPath,
|
|
199
199
|
['--import', 'tsx/esm', path.join(ROOT, 'supervisor/index.ts')],
|
|
@@ -203,6 +203,7 @@ function bootServer() {
|
|
|
203
203
|
let tunnelUrl = null;
|
|
204
204
|
let relayUrl = null;
|
|
205
205
|
let resolved = false;
|
|
206
|
+
let stderrBuf = '';
|
|
206
207
|
|
|
207
208
|
const doResolve = () => {
|
|
208
209
|
if (resolved) return;
|
|
@@ -239,12 +240,21 @@ function bootServer() {
|
|
|
239
240
|
};
|
|
240
241
|
|
|
241
242
|
child.stdout.on('data', handleData);
|
|
242
|
-
child.stderr.on('data',
|
|
243
|
+
child.stderr.on('data', (data) => {
|
|
244
|
+
stderrBuf += data.toString();
|
|
245
|
+
handleData(data);
|
|
246
|
+
});
|
|
243
247
|
|
|
244
248
|
process.on('SIGINT', () => child.kill('SIGINT'));
|
|
245
249
|
process.on('SIGTERM', () => child.kill('SIGTERM'));
|
|
246
250
|
|
|
247
|
-
child.on('exit', (code) =>
|
|
251
|
+
child.on('exit', (code) => {
|
|
252
|
+
if (!resolved) {
|
|
253
|
+
reject(new Error(stderrBuf.trim() || `Server exited with code ${code}`));
|
|
254
|
+
} else {
|
|
255
|
+
process.exit(code ?? 1);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
248
258
|
});
|
|
249
259
|
}
|
|
250
260
|
|
|
@@ -274,7 +284,16 @@ async function init() {
|
|
|
274
284
|
|
|
275
285
|
// Server + Tunnel
|
|
276
286
|
stepper.advance();
|
|
277
|
-
|
|
287
|
+
let result;
|
|
288
|
+
try {
|
|
289
|
+
result = await bootServer();
|
|
290
|
+
} catch (err) {
|
|
291
|
+
stepper.finish();
|
|
292
|
+
console.error(`\n ${c.red}Server failed to start:${c.reset}`);
|
|
293
|
+
console.error(` ${c.dim}${err.message}${c.reset}\n`);
|
|
294
|
+
process.exit(1);
|
|
295
|
+
}
|
|
296
|
+
const { child, tunnelUrl, relayUrl } = result;
|
|
278
297
|
stepper.advance();
|
|
279
298
|
|
|
280
299
|
stepper.finish();
|
|
@@ -302,7 +321,16 @@ async function start() {
|
|
|
302
321
|
stepper.advance(); // config exists
|
|
303
322
|
stepper.advance(); // starting
|
|
304
323
|
|
|
305
|
-
|
|
324
|
+
let result;
|
|
325
|
+
try {
|
|
326
|
+
result = await bootServer();
|
|
327
|
+
} catch (err) {
|
|
328
|
+
stepper.finish();
|
|
329
|
+
console.error(`\n ${c.red}Server failed to start:${c.reset}`);
|
|
330
|
+
console.error(` ${c.dim}${err.message}${c.reset}\n`);
|
|
331
|
+
process.exit(1);
|
|
332
|
+
}
|
|
333
|
+
const { child, tunnelUrl, relayUrl } = result;
|
|
306
334
|
stepper.advance();
|
|
307
335
|
|
|
308
336
|
stepper.finish();
|
package/package.json
CHANGED
package/supervisor/index.ts
CHANGED
|
@@ -114,6 +114,15 @@ export async function startSupervisor() {
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
// Start
|
|
117
|
+
server.on('error', (err: NodeJS.ErrnoException) => {
|
|
118
|
+
if (err.code === 'EADDRINUSE') {
|
|
119
|
+
log.error(`Port ${config.port} is already in use. Stop the other process or change the port in ${paths.config}`);
|
|
120
|
+
} else {
|
|
121
|
+
log.error(`Server error: ${err.message}`);
|
|
122
|
+
}
|
|
123
|
+
process.exit(1);
|
|
124
|
+
});
|
|
125
|
+
|
|
117
126
|
server.listen(config.port, () => {
|
|
118
127
|
log.ok(`Supervisor on http://localhost:${config.port}`);
|
|
119
128
|
log.ok(`Fluxy chat at http://localhost:${config.port}/fluxy`);
|
package/supervisor/tunnel.ts
CHANGED
|
@@ -61,6 +61,7 @@ export function startTunnel(port: number): Promise<string> {
|
|
|
61
61
|
proc.stdout?.on('data', onData);
|
|
62
62
|
proc.stderr?.on('data', onData);
|
|
63
63
|
proc.on('error', (e) => { clearTimeout(timeout); reject(e); });
|
|
64
|
+
proc.on('exit', (code) => { if (code !== 0) { clearTimeout(timeout); reject(new Error(`cloudflared exited with code ${code}`)); } });
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
|