-
-
Notifications
You must be signed in to change notification settings - Fork 359
Description
Hi there,
This is something I stumbled into due to our corporate proxy being HTTP-only, i.e. we set both HTTP_PROXY
and HTTPS_PROXY
env variables to the same http://proxy.company.com:8080
(note the http:// protocol).
By default Node's https
agent that axios
gets set up with:
const httpsAgent = new https.Agent({ family: config?.family ?? 4 }); |
does not cope with HTTP-only proxies for HTTPS URLs. It does not send the required
CONNECT
request to trigger tunneling requests to load https://
URLs.
This creates a problem where dts-plugin
is unable to fetch remote MFE typescript typings, i.e. @mf-types.zip
and @mf-types.d.ts
files from our dev environments when devs build the app on their laptops.
Workaround
I found that using https://github.com/TooTallNate/proxy-agents/tree/main/packages/https-proxy-agent does the trick:
const httpsProxyAgent = new HttpsProxyAgent(process.env.HTTP_PROXY || process.env.HTTPS_PROXY || 'http://proxy.company.com:8080');
So to set up axios.get
we'd have to pass in the httpsProxyAgent
and also disable axios
' own proxy logic via proxy: false
.
export async function axiosGet(url: string, config?: AxiosRequestConfig) {
const httpAgent = new http.Agent({ family: config?.family ?? 4 });
const httpsAgent = const httpsProxyAgent = new HttpsProxyAgent(process.env.HTTP_PROXY || process.env.HTTPS_PROXY || 'http://proxy.company.com:8080');
return axios.get(url, {
httpAgent,
httpsAgent,
proxy: false, // Need to allow control over this via dts-plugin options?
...
});
}
Maybe there are better ways - but the above one definitely works in our corporate environment.
I've been also experimenting and trying to find external workaround to somehow monkey-patch axios and http methods project-wide, but no success. So decided to create this ticket instead, as at the moment only dts-plugin
in our repo is making HTTP requests when building our MFE.
What do you think?
Thanks
Reproduction
Used Package Manager
yarn
System Info
System:
OS: macOS 15.5
CPU: (14) arm64 Apple M4 Pro
Memory: 112.27 MB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.14.0/bin/yarn
npm: 11.4.0 - ~/.nvm/versions/node/v22.14.0/bin/npm
Validations
- Read the docs.
- Read the common issues list.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Module federation issue and not a framework-specific issue.
- The provided reproduction is a minimal reproducible example of the bug.