24 lines
472 B
TypeScript
24 lines
472 B
TypeScript
import http from 'http';
|
|
|
|
class Response extends http.IncomingMessage {
|
|
body?: string;
|
|
}
|
|
|
|
export
|
|
function get (
|
|
headers: http.OutgoingHttpHeaders = {}
|
|
): Promise<Response> {
|
|
return new Promise ((resolve) => {
|
|
http.get ('http://localhost:3000', { headers }, (res: Response) => {
|
|
let body = '';
|
|
res.on ('data', (d) => {
|
|
body += d;
|
|
});
|
|
res.on ('end', () => {
|
|
res.body = body;
|
|
resolve (res);
|
|
});
|
|
});
|
|
});
|
|
}
|