Skip to content

Commit 71bc8ec

Browse files
hdt12a1karpikpl
andauthored
CUSTOM_CA_PATH option for HTTPS PROXY - feature/https-proxy (#162)
* . * Update Readme and version 2.0.2 --------- Co-authored-by: Piotr Karpala <[email protected]>
1 parent cb64f7b commit 71bc8ec

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ Variables required for GitHub Auth are:
178178

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

181+
For custom CA use environment variable `CUSTOM_CA_PATH` to load the certificate into proxy agent options.
182+
181183
## Install Dependencies
182184

183185
```bash

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "copilot-metrics-viewer",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"private": true,
55
"type": "module",
66
"scripts": {

server/plugins/http-agent.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
import { ProxyAgent, setGlobalDispatcher } from "undici";
2-
import { ofetch } from "ofetch";
1+
import { ProxyAgent, setGlobalDispatcher } from 'undici';
2+
import { ofetch } from 'ofetch';
3+
import { readFileSync } from 'fs';
34

45
export default defineNitroPlugin((nitro) => {
56
if (process.env.HTTP_PROXY) {
6-
const proxyAgent = new ProxyAgent(process.env.HTTP_PROXY);
7+
const tlsOptions = process.env.CUSTOM_CA_PATH ? {
8+
tls: {
9+
ca: [
10+
readFileSync(process.env.CUSTOM_CA_PATH)
11+
]
12+
}
13+
} : {};
14+
15+
const proxyAgent = new ProxyAgent({
16+
uri: process.env.HTTP_PROXY,
17+
...tlsOptions
18+
});
19+
720
setGlobalDispatcher(proxyAgent);
8-
const fetchWithProxy = ofetch.create({ dispatcher: proxyAgent });
9-
nitro.hooks.hook("request", (context) => {
21+
22+
const fetchWithProxy = ofetch.create({
23+
dispatcher: proxyAgent,
24+
httpsProxy: process.env.HTTP_PROXY,
25+
proxy: false
26+
});
27+
28+
nitro.hooks.hook('request', (context) => {
1029
context.fetch = fetchWithProxy;
1130
});
1231
}
13-
});
32+
});

0 commit comments

Comments
 (0)