Browse Source

feat: support configurable CORS proxy server (#383)

imwald
Daniel Vergara 9 months ago committed by GitHub
parent
commit
b4f972dcbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      Dockerfile
  2. 17
      docker-compose.yml
  3. 4
      src/hooks/useFetchWebMetadata.tsx

12
Dockerfile

@ -1,10 +1,18 @@
# Step 1: Build the application # Step 1: Build the application
FROM node:20-alpine as builder FROM node:20-alpine as builder
ARG VITE_PROXY_SERVER
ENV VITE_PROXY_SERVER=${VITE_PROXY_SERVER}
WORKDIR /app WORKDIR /app
COPY . .
RUN npm install && npm run build # 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 # Step 2: Final container with Nginx and embedded config
FROM nginx:alpine FROM nginx:alpine

17
docker-compose.yml

@ -6,6 +6,23 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
args:
VITE_PROXY_SERVER: http://localhost:8090
ports: ports:
- "8089:80" - "8089:80"
restart: unless-stopped 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:

4
src/hooks/useFetchWebMetadata.tsx

@ -4,6 +4,10 @@ import webService from '@/services/web.service'
export function useFetchWebMetadata(url: string) { export function useFetchWebMetadata(url: string) {
const [metadata, setMetadata] = useState<TWebMetadata>({}) const [metadata, setMetadata] = useState<TWebMetadata>({})
const proxyServer = import.meta.env.VITE_PROXY_SERVER
if (proxyServer) {
url = `${proxyServer}/sites/${encodeURIComponent(url)}`
}
useEffect(() => { useEffect(() => {
webService.fetchWebMetadata(url).then((metadata) => setMetadata(metadata)) webService.fetchWebMetadata(url).then((metadata) => setMetadata(metadata))

Loading…
Cancel
Save