From 4ed23bb6ef24f384169433daa30ee0f8c54b3d3a Mon Sep 17 00:00:00 2001 From: badbl0cks <4161747+badbl0cks@users.noreply.github.com> Date: Sun, 8 Feb 2026 09:02:51 -0800 Subject: [PATCH] Fix wireguard proxy not working when deployed due to bun's fetch not supporting undici dispatchers --- Dockerfile | 13 ++++++++----- deploy/docker-compose.yml | 1 + package.json | 3 ++- src/lib/HttpFetchClient.ts | 16 +++++++++++----- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d8fa4f..c3a7015 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,12 +24,15 @@ ENV NODE_ENV=production #RUN bun test RUN bun run build-remote -# copy production dependencies and source code into final image -FROM base AS release +# copy production dependencies and source code into final image +# and run with node to avoid some random issues with bun +# (e.g. bun's fetch doesn't support dispatchers) +FROM node:20-slim AS release +WORKDIR /usr/src/app COPY --from=install /temp/prod/node_modules node_modules COPY --from=prerelease /usr/src/app/dist ./dist -COPY --from=prerelease /usr/src/app/package.json . +COPY --from=prerelease /usr/src/app/package.json ./ -USER bun +USER node EXPOSE 4321 -ENTRYPOINT ["bun", "run", "./dist/server/entry.mjs"] +ENTRYPOINT ["node", "./dist/server/entry.mjs"] diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index ab1a62f..8cfaefe 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -29,6 +29,7 @@ services: cap_add: - NET_ADMIN container_name: wireguard + hostname: wireguard environment: - VPN_SERVICE_PROVIDER=custom - VPN_TYPE=wireguard diff --git a/package.json b/package.json index b99ae72..69d4bab 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "version": "0.0.1", "scripts": { "dev": "astro dev", - "start": "bun run ./dist/server/entry.mjs", + "start-bun": "bun run ./dist/server/entry.mjs", + "start": "node ./dist/server/entry.mjs", "check": "astro check", "build-only": "astro build", "build": "astro check && astro build", diff --git a/src/lib/HttpFetchClient.ts b/src/lib/HttpFetchClient.ts index 0b3e7f1..4319c5e 100644 --- a/src/lib/HttpFetchClient.ts +++ b/src/lib/HttpFetchClient.ts @@ -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) => { @@ -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) => { 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) => { 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) => { 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) => { const response = await ofetch(url, { method: "DELETE", headers, dispatcher: wireguardDispatcher, + timeout: TIMEOUT, }); - return response.json(); + return response; }, }; export default httpFetchClient;