Repository navigation
Expand file tree
/
Copy pathaauth-run-all.js
More file actions
56 lines (48 loc) · 1.76 KB
/
Copy pathaauth-run-all.js
File metadata and controls
56 lines (48 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
/**
* Spawns all three AAuth dummy HTTP servers in one parent process so a single
* `npm run aauth:all` boots the full E2E fixture set.
*
* Press Ctrl+C to stop all children.
*/
import { spawn } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const SERVERS_DIR = path.join(__dirname, '..', 'servers');
const TARGETS = [
{ name: 'signed', script: 'aauth-signed-http-server.js', port: 9701 },
{ name: 'challenge', script: 'aauth-challenge-http-server.js', port: 9702 },
{ name: 'bearer', script: 'bearer-token-http-server.js', port: 9703 },
];
const children = [];
let shuttingDown = false;
function shutdown(reason) {
if (shuttingDown) return;
shuttingDown = true;
// biome-ignore lint/suspicious/noConsole: cli output
console.log(`\n[aauth-run-all] shutting down (${reason})`);
for (const c of children) {
if (!c.killed) c.kill('SIGINT');
}
setTimeout(() => process.exit(0), 500);
}
for (const t of TARGETS) {
const child = spawn('node', [path.join(SERVERS_DIR, t.script)], {
stdio: ['ignore', 'inherit', 'inherit'],
env: { ...process.env, PORT: String(t.port) },
});
child.on('exit', (code) => {
// biome-ignore lint/suspicious/noConsole: cli output
console.log(`[aauth-run-all] ${t.name} exited code=${code}`);
if (!shuttingDown) shutdown(`${t.name} exited`);
});
children.push(child);
}
process.on('SIGINT', () => shutdown('SIGINT'));
process.on('SIGTERM', () => shutdown('SIGTERM'));
// biome-ignore lint/suspicious/noConsole: cli output
console.log(
`[aauth-run-all] started ${TARGETS.length} servers ` +
`(${TARGETS.map((t) => `${t.name}:${t.port}`).join(', ')}). Ctrl+C to stop.`
);