Skip to content

Commit

Permalink
CUSTOM_CA_PATH option for HTTPS PROXY - feature/https-proxy (#162)
Browse files Browse the repository at this point in the history
* .

* Update Readme and version 2.0.2

---------

Co-authored-by: Piotr Karpala <[email protected]>
  • Loading branch information
hdt12a1 and karpikpl authored Feb 18, 2025
1 parent cb64f7b commit 71bc8ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ Variables required for GitHub Auth are:

Solution supports HTTP Proxy settings when running in corporate environment. Simple set `HTTP_PROXY` environment variable.

For custom CA use environment variable `CUSTOM_CA_PATH` to load the certificate into proxy agent options.

## Install Dependencies

```bash
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "copilot-metrics-viewer",
"version": "2.0.1",
"version": "2.0.2",
"private": true,
"type": "module",
"scripts": {
Expand Down
31 changes: 25 additions & 6 deletions server/plugins/http-agent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import { ProxyAgent, setGlobalDispatcher } from "undici";
import { ofetch } from "ofetch";
import { ProxyAgent, setGlobalDispatcher } from 'undici';
import { ofetch } from 'ofetch';
import { readFileSync } from 'fs';

export default defineNitroPlugin((nitro) => {
if (process.env.HTTP_PROXY) {
const proxyAgent = new ProxyAgent(process.env.HTTP_PROXY);
const tlsOptions = process.env.CUSTOM_CA_PATH ? {
tls: {
ca: [
readFileSync(process.env.CUSTOM_CA_PATH)
]
}
} : {};

const proxyAgent = new ProxyAgent({
uri: process.env.HTTP_PROXY,
...tlsOptions
});

setGlobalDispatcher(proxyAgent);
const fetchWithProxy = ofetch.create({ dispatcher: proxyAgent });
nitro.hooks.hook("request", (context) => {

const fetchWithProxy = ofetch.create({
dispatcher: proxyAgent,
httpsProxy: process.env.HTTP_PROXY,
proxy: false
});

nitro.hooks.hook('request', (context) => {
context.fetch = fetchWithProxy;
});
}
});
});

0 comments on commit 71bc8ec

Please sign in to comment.