Polyfill fetch

Summary: Provide server add-on writers with a well-known fetch API

Reviewed By: mweststrate

Differential Revision: D34447630

fbshipit-source-id: 70386940c12f9e53aa97b3530a7edf1d40b5f2e2
This commit is contained in:
Andrey Goncharov
2022-02-28 03:50:34 -08:00
committed by Facebook GitHub Bot
parent aec05533d7
commit 3ec5b56263
4 changed files with 74 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
* @format
*/
import './utils/fetch-polyfill';
import EventEmitter from 'events';
import {ServerController} from './comms/ServerController';
import {CertificateExchangeMedium} from './utils/CertificateProvider';

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import nodeFetch, {
Headers as HeadersNF,
Request as RequestNF,
Response as ResponseNF,
} from 'node-fetch';
declare module globalThis {
// eslint-disable-next-line no-var
var fetch: typeof nodeFetch;
// eslint-disable-next-line no-var
var Headers: typeof HeadersNF;
// eslint-disable-next-line no-var
var Request: typeof RequestNF;
// eslint-disable-next-line no-var
var Response: typeof ResponseNF;
}
if (!globalThis.fetch) {
globalThis.fetch = nodeFetch;
globalThis.Headers = HeadersNF;
globalThis.Request = RequestNF;
globalThis.Response = ResponseNF;
}