Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

.vscode
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions lib/node-loader-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/basic.test.js
Original file line number Diff line number Diff line change
@@ -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"
);
Expand Down