GET a path from a running viewer, with a valid loopback Host.
(port: number, requestPath: string)
| 49 | |
| 50 | /** GET a path from a running viewer, with a valid loopback Host. */ |
| 51 | function get(port: number, requestPath: string): Promise<{ status: number; body: string }> { |
| 52 | return new Promise((resolve, reject) => { |
| 53 | const req = http.request( |
| 54 | { host: '127.0.0.1', port, path: requestPath, method: 'GET' }, |
| 55 | (res) => { |
| 56 | const chunks: Buffer[] = []; |
| 57 | res.on('data', (c: Buffer) => chunks.push(c)); |
| 58 | res.on('end', () => |
| 59 | resolve({ status: res.statusCode ?? 0, body: Buffer.concat(chunks).toString('utf-8') }) |
| 60 | ); |
| 61 | } |
| 62 | ); |
| 63 | req.on('error', reject); |
| 64 | req.end(); |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Start `codegraph ui` and wait for the URL it prints. |
no test coverage detected