MCPcopy Create free account
hub / github.com/EvoMap/evolver / startStatusServer

Function startStatusServer

test/lifecycleProxyHealth.test.js:13–55  ·  view source on GitHub ↗
(mode, token)

Source from the content-addressed store, hash-verified

11const { writeSettings } = require('../src/proxy/server/settings');
12
13function startStatusServer(mode, token) {
14 const child = spawn(process.execPath, ['-e', `
15const http = require('http');
16const mode = process.env.TEST_PROXY_MODE;
17const token = process.env.TEST_PROXY_TOKEN;
18const server = http.createServer((req, res) => {
19 if (mode === 'auth') {
20 if (req.headers.authorization !== 'Bearer ' + token) {
21 res.writeHead(401, { 'content-type': 'application/json' });
22 res.end(JSON.stringify({ error: 'unauthorized' }));
23 return;
24 }
25 res.writeHead(200, { 'content-type': 'application/json' });
26 res.end(JSON.stringify({
27 status: 'running',
28 proxy_protocol_version: '1.0.0',
29 schema_version: '1.0.0',
30 }));
31 return;
32 }
33 res.writeHead(200, { 'content-type': 'application/json' });
34 res.end(JSON.stringify({ ok: true }));
35});
36server.listen(0, '127.0.0.1', () => {
37 process.stdout.write('http://127.0.0.1:' + server.address().port + '\\n');
38});
39process.on('SIGTERM', () => server.close(() => process.exit(0)));
40`], {
41 env: { PATH: process.env.PATH, TEST_PROXY_MODE: mode, TEST_PROXY_TOKEN: token || '' },
42 stdio: ['ignore', 'pipe', 'inherit'],
43 });
44 return new Promise((resolve, reject) => {
45 let settled = false;
46 child.once('error', reject);
47 child.stdout.once('data', (chunk) => {
48 settled = true;
49 resolve({ child, url: String(chunk).trim() });
50 });
51 child.once('exit', (code) => {
52 if (!settled) reject(new Error(`status server exited early: ${code}`));
53 });
54 });
55}
56
57function close(child) {
58 return new Promise((resolve) => {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected