mirror of
https://github.com/vale981/apollo-server
synced 2025-03-16 07:46:54 -04:00
19 lines
459 B
TypeScript
19 lines
459 B
TypeScript
![]() |
import { IncomingMessage } from 'http';
|
||
|
|
||
|
export function convertNodeHttpToRequest(req: IncomingMessage): Request {
|
||
|
const headers = new Headers();
|
||
|
Object.keys(req.headers).forEach(key => {
|
||
|
const values = req.headers[key];
|
||
|
if (Array.isArray(values)) {
|
||
|
values.forEach(value => headers.append(key, value));
|
||
|
} else {
|
||
|
headers.append(key, values);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return new Request(req.url, {
|
||
|
headers,
|
||
|
method: req.method,
|
||
|
});
|
||
|
}
|