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
All checks were successful
Build And Deploy / build-and-deploy (push) Successful in 44s
This commit is contained in:
parent
6c56b203d3
commit
4ed23bb6ef
4 changed files with 22 additions and 11 deletions
11
Dockerfile
11
Dockerfile
|
|
@ -25,11 +25,14 @@ ENV NODE_ENV=production
|
|||
RUN bun run build-remote
|
||||
|
||||
# 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=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"]
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ services:
|
|||
cap_add:
|
||||
- NET_ADMIN
|
||||
container_name: wireguard
|
||||
hostname: wireguard
|
||||
environment:
|
||||
- VPN_SERVICE_PROVIDER=custom
|
||||
- VPN_TYPE=wireguard
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue