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

@ -25,11 +25,14 @@ ENV NODE_ENV=production
RUN bun run build-remote RUN bun run build-remote
# copy production dependencies and source code into final image # copy production dependencies and source code into final image
FROM base AS release # 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=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/dist ./dist 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 EXPOSE 4321
ENTRYPOINT ["bun", "run", "./dist/server/entry.mjs"] ENTRYPOINT ["node", "./dist/server/entry.mjs"]

View file

@ -29,6 +29,7 @@ services:
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
container_name: wireguard container_name: wireguard
hostname: wireguard
environment: environment:
- VPN_SERVICE_PROVIDER=custom - VPN_SERVICE_PROVIDER=custom
- VPN_TYPE=wireguard - VPN_TYPE=wireguard

View file

@ -4,7 +4,8 @@
"version": "0.0.1", "version": "0.0.1",
"scripts": { "scripts": {
"dev": "astro dev", "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", "check": "astro check",
"build-only": "astro build", "build-only": "astro build",
"build": "astro check && astro build", "build": "astro check && astro build",

View file

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