Skip to content

Commit 607f295

Browse files
authoredMay 12, 2023
fix: respect custom fetch implementation (#108)
1 parent 0b5197d commit 607f295

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { URL } from "url";
22
import { Parser } from "htmlparser2";
3-
import fetch from "node-fetch";
3+
import nodeFetch from "node-fetch";
44
import UnexpectedError from "./unexpectedError";
55
import { schema, keys } from "./schema";
66
import { Metadata, Opts } from "./types";
@@ -41,14 +41,14 @@ function unfurl(url: string, opts?: Opts): Promise<Metadata> {
4141

4242
return getPage(url, opts)
4343
.then(getMetadata(url, opts))
44-
.then(getRemoteMetadata(url))
44+
.then(getRemoteMetadata(url, opts))
4545
.then(parse(url));
4646
}
4747

4848
async function getPage(url: string, opts: Opts) {
4949
const res = await (opts.fetch
5050
? opts.fetch(url)
51-
: fetch(new URL(url), {
51+
: nodeFetch(new URL(url), {
5252
headers: opts.headers,
5353
size: opts.size,
5454
follow: opts.follow,
@@ -122,7 +122,7 @@ async function getPage(url: string, opts: Opts) {
122122
return buf.toString();
123123
}
124124

125-
function getRemoteMetadata(url: string) {
125+
function getRemoteMetadata(url: string, { fetch = nodeFetch }: Opts) {
126126
return async function ({ oembed, metadata }) {
127127
if (!oembed) {
128128
return metadata;

0 commit comments

Comments
 (0)
Please sign in to comment.