Skip to content

Commit 493c365

Browse files
Djiitkarpikpl
andauthored
feat: allow usage behind a corporate proxy (#152)
* feat: allow usage behind a corporate proxy * Update to Readme --------- Co-authored-by: Piotr Karpala <[email protected]>
1 parent 2c54629 commit 493c365

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ NUXT_SESSION_PASSWORD=something_long_and_random_thats_at_least_32_characters
2323

2424
# for Github OAuth
2525
NUXT_OAUTH_GITHUB_CLIENT_ID=
26-
NUXT_OAUTH_GITHUB_CLIENT_SECRET=
26+
NUXT_OAUTH_GITHUB_CLIENT_SECRET=
27+
28+
# to use a corporate proxy
29+
# HTTP_PROXY=http://proxy.company.com:8080

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ Variables required for GitHub Auth are:
174174
>[!WARNING]
175175
> Only users with permissions (scopes listed in [NUXT_GITHUB_TOKEN](#NUXT_GITHUB_TOKEN)) can view copilot metrics, GitHub uses the authenticated users permissions to make API calls for data.
176176
177+
#### Support for HTTP Proxy HTTP_PROXY
178+
179+
Solution supports HTTP Proxy settings when running in corporate environment. Simple set `HTTP_PROXY` environment variable.
180+
177181
## Install Dependencies
178182

179183
```bash

nuxt.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ export default defineNuxtConfig({
6969
scope: ''
7070
}
7171
},
72-
72+
nitro: {
73+
plugins: [
74+
'plugins/http-agent',
75+
],
76+
},
7377
runtimeConfig: {
7478
githubToken: '',
7579
session: {

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"nuxt": "^3.15.3",
2424
"nuxt-auth-utils": "^0.5.7",
2525
"roboto-fontface": "^0.10.0",
26+
"undici": "^7.3.0",
2627
"vue": "latest",
2728
"vue-chartjs": "^5.3.2",
2829
"vuetify": "^3.7.3",

server/plugins/http-agent.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ProxyAgent, setGlobalDispatcher } from "undici";
2+
import { ofetch } from "ofetch";
3+
4+
export default defineNitroPlugin((nitro) => {
5+
if (process.env.HTTP_PROXY) {
6+
const proxyAgent = new ProxyAgent(process.env.HTTP_PROXY);
7+
setGlobalDispatcher(proxyAgent);
8+
const fetchWithProxy = ofetch.create({ dispatcher: proxyAgent });
9+
nitro.hooks.hook("request", (context) => {
10+
context.fetch = fetchWithProxy;
11+
});
12+
}
13+
});

0 commit comments

Comments
 (0)