From ec3a2c01dfd4ecdacd9550e711f1cafb867ac455 Mon Sep 17 00:00:00 2001 From: "William Bernting (whf962)" Date: Thu, 2 Dec 2021 08:35:31 +0100 Subject: [PATCH 1/2] Ignore .vscode directory --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6704566..050779a 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,5 @@ dist # TernJS port file .tern-port + +.vscode \ No newline at end of file From bf79ccc91cbddc8b07630dcd78b23dc8c5ae7e8a Mon Sep 17 00:00:00 2001 From: "William Bernting (whf962)" Date: Thu, 2 Dec 2021 08:35:51 +0100 Subject: [PATCH 2/2] Support passing down fetch options via loader config --- README.md | 19 +++++++++++++++++++ lib/node-loader-http.js | 7 +++++-- test/basic.test.js | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 198ff84..a52e5dd 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,25 @@ Now run node with the `--experimental-loader` flag: node --experimental-loader @node-loader/http file.js ``` +If you use @node-loader/core, you can pass down options to the loader. + +```js +const HttpsProxyAgent = require("https-proxy-agent"); + +export default { + loaders: [ + { + options: { + fetchOptions: { + agent: new HttpsProxyAgent("http://123.123.123.123"), + }, + }, + loader: httpLoader, + }, + ], +}; +``` + ## Semantics This project uses [node-fetch](https://github.com/node-fetch/node-fetch) to implement familiar HTTP semantics, diff --git a/lib/node-loader-http.js b/lib/node-loader-http.js index d98716e..79a0c56 100644 --- a/lib/node-loader-http.js +++ b/lib/node-loader-http.js @@ -25,7 +25,7 @@ export function resolve(specifier, context, defaultResolve) { return defaultResolve(specifier, context, defaultResolve); } -export async function load(url, context, defaultLoad) { +export async function load(url, context, defaultLoad, loaderOptions) { if (useLoader(url)) { let format; // TODO: maybe change to content-type / mime type check rather than file extensions @@ -46,7 +46,10 @@ export async function load(url, context, defaultLoad) { let source; - const httpResponse = await fetch(url); + const httpResponse = await fetch( + url, + loaderOptions ? loaderOptions.fetchOptions : undefined + ); if (httpResponse.ok) { source = await httpResponse.text(); diff --git a/test/basic.test.js b/test/basic.test.js index faf17b8..8eea90d 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1,7 +1,7 @@ import assert from "assert"; describe(`basic http / https tests`, () => { - it(`can load a module over http`, async () => { + it.only(`can load a module over http`, async () => { const ns = await import( "http://unpkg.com/single-spa@5.5.5/lib/esm/single-spa.dev.js" );