diff --git a/Dockerfile b/Dockerfile index 1975bdd9..8d9648d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,8 @@ FROM registry.access.redhat.com/ubi9/nodejs-20 AS builder RUN npm install -g yarn -ENV VITE_BACKEND_BASE_URL=http://localhost:8080 +ARG BACKEND_URL=http://localhost:8080 +ENV VITE_BACKEND_BASE_URL=${BACKEND_URL} WORKDIR /app COPY package.json yarn.lock ./ diff --git a/vite.config.ts b/vite.config.ts index 233f46b2..f850c52c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,6 +3,11 @@ import type { InlineConfig } from "vitest"; import type { UserConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import tsconfigPaths from 'vite-tsconfig-paths'; +import { loadEnv } from 'vite'; + +const env = loadEnv('all', process.cwd(), 'VITE_'); +const API_URL = `${env.VITE_BACKEND_API_URL ?? 'http://localhost:8080'}`; +const PORT = `${env.VITE_PORT ?? '3000'}`; type ViteConfig = UserConfig & { test: InlineConfig }; const config: ViteConfig = { @@ -10,12 +15,12 @@ const config: ViteConfig = { server: { proxy: { "/api": { - target: "http://localhost:8080", + target: API_URL, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, "/api"), // Keep '/api' prefix }, }, - port: 3000, + port: PORT, }, test: { // 👋 add the line below to add jsdom to vite