|
1 | 1 | import { URL } from "url";
|
2 | 2 | import { Parser } from "htmlparser2";
|
3 |
| -import fetch from "node-fetch"; |
| 3 | +import nodeFetch from "node-fetch"; |
4 | 4 | import UnexpectedError from "./unexpectedError";
|
5 | 5 | import { schema, keys } from "./schema";
|
6 | 6 | import { Metadata, Opts } from "./types";
|
@@ -41,14 +41,14 @@ function unfurl(url: string, opts?: Opts): Promise<Metadata> {
|
41 | 41 |
|
42 | 42 | return getPage(url, opts)
|
43 | 43 | .then(getMetadata(url, opts))
|
44 |
| - .then(getRemoteMetadata(url)) |
| 44 | + .then(getRemoteMetadata(url, opts)) |
45 | 45 | .then(parse(url));
|
46 | 46 | }
|
47 | 47 |
|
48 | 48 | async function getPage(url: string, opts: Opts) {
|
49 | 49 | const res = await (opts.fetch
|
50 | 50 | ? opts.fetch(url)
|
51 |
| - : fetch(new URL(url), { |
| 51 | + : nodeFetch(new URL(url), { |
52 | 52 | headers: opts.headers,
|
53 | 53 | size: opts.size,
|
54 | 54 | follow: opts.follow,
|
@@ -122,7 +122,7 @@ async function getPage(url: string, opts: Opts) {
|
122 | 122 | return buf.toString();
|
123 | 123 | }
|
124 | 124 |
|
125 |
| -function getRemoteMetadata(url: string) { |
| 125 | +function getRemoteMetadata(url: string, { fetch = nodeFetch }: Opts) { |
126 | 126 | return async function ({ oembed, metadata }) {
|
127 | 127 | if (!oembed) {
|
128 | 128 | return metadata;
|
|
0 commit comments