From b4f972dcbb5b680cff91108d89c7fb6299feffd4 Mon Sep 17 00:00:00 2001 From: Daniel Vergara Date: Fri, 13 Jun 2025 23:16:02 -0600 Subject: [PATCH] feat: support configurable CORS proxy server (#383) --- Dockerfile | 14 +++++++++++--- docker-compose.yml | 17 +++++++++++++++++ src/hooks/useFetchWebMetadata.tsx | 4 ++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2ead3f17..e658c1da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,18 @@ # Step 1: Build the application FROM node:20-alpine as builder -WORKDIR /app -COPY . . +ARG VITE_PROXY_SERVER +ENV VITE_PROXY_SERVER=${VITE_PROXY_SERVER} -RUN npm install && npm run build +WORKDIR /app + +# Copy package files first +COPY package*.json ./ +RUN npm install + +# Copy the source code to prevent invaliding cache whenever there is a change in the code +COPY . . +RUN npm run build # Step 2: Final container with Nginx and embedded config FROM nginx:alpine diff --git a/docker-compose.yml b/docker-compose.yml index 7c58d0ec..788d389e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,23 @@ services: build: context: . dockerfile: Dockerfile + args: + VITE_PROXY_SERVER: http://localhost:8090 ports: - "8089:80" restart: unless-stopped + networks: + - jumble + + proxy-server: + image: ghcr.io/danvergara/jumble-proxy-server:latest + environment: + - ALLOW_ORIGIN=http://localhost:8089 + - PORT=8080 + ports: + - "8090:8080" + networks: + - jumble + +networks: + jumble: diff --git a/src/hooks/useFetchWebMetadata.tsx b/src/hooks/useFetchWebMetadata.tsx index 5f6a8d30..dff352d6 100644 --- a/src/hooks/useFetchWebMetadata.tsx +++ b/src/hooks/useFetchWebMetadata.tsx @@ -4,6 +4,10 @@ import webService from '@/services/web.service' export function useFetchWebMetadata(url: string) { const [metadata, setMetadata] = useState({}) + const proxyServer = import.meta.env.VITE_PROXY_SERVER + if (proxyServer) { + url = `${proxyServer}/sites/${encodeURIComponent(url)}` + } useEffect(() => { webService.fetchWebMetadata(url).then((metadata) => setMetadata(metadata))