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