Fix wireguard proxy not working when deployed due to bun's fetch not supporting undici dispatchers
All checks were successful
Build And Deploy / build-and-deploy (push) Successful in 44s

This commit is contained in:
badblocks 2026-02-08 09:02:51 -08:00
parent 6c56b203d3
commit 4ed23bb6ef
No known key found for this signature in database
4 changed files with 22 additions and 11 deletions

View file

@ -2,6 +2,7 @@ import { ofetch } from "ofetch";
import { ProxyAgent } from "undici";
const wireguardDispatcher = new ProxyAgent("http://wireguard:8888");
const TIMEOUT = 5000;
const httpFetchClient = {
get: async (url: string, headers: Record<string, string>) => {
@ -9,9 +10,10 @@ const httpFetchClient = {
method: "GET",
headers,
dispatcher: wireguardDispatcher,
timeout: TIMEOUT,
});
return response.json();
return response;
},
post: async (url: string, body: JSON, headers: Record<string, string>) => {
const response = await ofetch(url, {
@ -19,9 +21,10 @@ const httpFetchClient = {
headers,
body: JSON.stringify(body),
dispatcher: wireguardDispatcher,
timeout: TIMEOUT,
});
return response.json();
return response;
},
put: async (url: string, body: JSON, headers: Record<string, string>) => {
const response = await ofetch(url, {
@ -29,9 +32,10 @@ const httpFetchClient = {
headers,
body: JSON.stringify(body),
dispatcher: wireguardDispatcher,
timeout: TIMEOUT,
});
return response.json();
return response;
},
patch: async (url: string, body: JSON, headers: Record<string, string>) => {
const response = await ofetch(url, {
@ -39,18 +43,20 @@ const httpFetchClient = {
headers,
body: JSON.stringify(body),
dispatcher: wireguardDispatcher,
timeout: TIMEOUT,
});
return response.json();
return response;
},
delete: async (url: string, headers: Record<string, string>) => {
const response = await ofetch(url, {
method: "DELETE",
headers,
dispatcher: wireguardDispatcher,
timeout: TIMEOUT,
});
return response.json();
return response;
},
};
export default httpFetchClient;