(url, token)
| 138 | } |
| 139 | |
| 140 | function _proxyReachable(url, token) { |
| 141 | if (!_isLoopbackProxyUrl(url) || !token) return false; |
| 142 | try { |
| 143 | const { execFileSync } = require('child_process'); |
| 144 | execFileSync(process.execPath, ['-e', ` |
| 145 | const fs = require('fs'); |
| 146 | const http = require('http'); |
| 147 | const url = process.argv[1].replace(/\\/+$/, '') + '/proxy/status'; |
| 148 | const token = fs.readFileSync(0, 'utf8').trim(); |
| 149 | if (!token) process.exit(1); |
| 150 | const 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 | }); |
| 167 | req.setTimeout(700, () => req.destroy(new Error('timeout'))); |
| 168 | req.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 | |
| 176 | function _proxyHealthyIfExpected() { |
| 177 | if (!_proxyExpected()) return true; |
no test coverage detected