(requestPath: string)
| 39 | `; |
| 40 | |
| 41 | function request(requestPath: string): Promise<{ status: number; body: string; type?: string }> { |
| 42 | return new Promise((resolve, reject) => { |
| 43 | const req = http.request( |
| 44 | { |
| 45 | host: '127.0.0.1', |
| 46 | port: server.port, |
| 47 | path: requestPath, |
| 48 | method: 'GET', |
| 49 | headers: { Host: `127.0.0.1:${server.port}` }, |
| 50 | setHost: false, |
| 51 | }, |
| 52 | (res) => { |
| 53 | const chunks: Buffer[] = []; |
| 54 | res.on('data', (c: Buffer) => chunks.push(c)); |
| 55 | res.on('end', () => |
| 56 | resolve({ |
| 57 | status: res.statusCode ?? 0, |
| 58 | body: Buffer.concat(chunks).toString('utf-8'), |
| 59 | type: res.headers['content-type'], |
| 60 | }) |
| 61 | ); |
| 62 | } |
| 63 | ); |
| 64 | req.on('error', reject); |
| 65 | req.end(); |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | interface SseEvent { |
| 70 | event: string; |
no test coverage detected