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

Function _proxyReachable

src/adapters/scripts/evolver-session-start.js:140–174  ·  view source on GitHub ↗
(url, token)

Source from the content-addressed store, hash-verified

138}
139
140function _proxyReachable(url, token) {
141 if (!_isLoopbackProxyUrl(url) || !token) return false;
142 try {
143 const { execFileSync } = require('child_process');
144 execFileSync(process.execPath, ['-e', `
145const fs = require('fs');
146const http = require('http');
147const url = process.argv[1].replace(/\\/+$/, '') + '/proxy/status';
148const token = fs.readFileSync(0, 'utf8').trim();
149if (!token) process.exit(1);
150const req = http.get(url, { headers: { Authorization: 'Bearer ' + token } }, (res) => {
151 let body = '';
152 res.setEncoding('utf8');
153 res.on('data', (chunk) => {
154 body += chunk;
155 if (body.length > 1024 * 1024) req.destroy(new Error('response too large'));
156 });
157 res.on('end', () => {
158 if (res.statusCode < 200 || res.statusCode >= 300) process.exit(1);
159 let parsed;
160 try { parsed = JSON.parse(body); } catch (_) { process.exit(1); }
161 if (parsed && parsed.status === 'running' && (parsed.proxy_protocol_version || parsed.schema_version || parsed.node_id != null)) {
162 process.exit(0);
163 }
164 process.exit(1);
165 });
166});
167req.setTimeout(700, () => req.destroy(new Error('timeout')));
168req.on('error', () => process.exit(1));
169`, url], { input: String(token), stdio: ['pipe', 'ignore', 'ignore'], timeout: 1200, windowsHide: true });
170 return true;
171 } catch (_) {
172 return false;
173 }
174}
175
176function _proxyHealthyIfExpected() {
177 if (!_proxyExpected()) return true;

Callers 2

_proxyHealthyIfExpectedFunction · 0.85

Calls 1

_isLoopbackProxyUrlFunction · 0.85

Tested by

no test coverage detected