build(frontend): load backend url for vite dev proxy from env

This commit is contained in:
2025-03-07 16:31:41 +01:00
parent 5f1404c7d7
commit d4f194b146
4 changed files with 26 additions and 3 deletions

2
frontend/.env.sample Normal file
View File

@ -0,0 +1,2 @@
# Backend URL to use for the vite development proxy
VITE_BACKEND_URL=http://localhost:3000

View File

@ -21,6 +21,7 @@
"@tailwindcss/typography": "^0.5.15",
"@tailwindcss/vite": "^4.0.0",
"@tsconfig/svelte": "^5.0.4",
"@types/node": "^22.13.9",
"flowbite": "^3.1.2",
"flowbite-svelte": "^0.48.4",
"flowbite-svelte-icons": "^2.0.2",
@ -622,6 +623,16 @@
"integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==",
"license": "MIT"
},
"node_modules/@types/node": {
"version": "22.13.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.9.tgz",
"integrity": "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.20.0"
}
},
"node_modules/@types/resolve": {
"version": "1.20.2",
"resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz",
@ -4601,6 +4612,13 @@
"node": ">=18.17"
}
},
"node_modules/undici-types": {
"version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
"dev": true,
"license": "MIT"
},
"node_modules/unified": {
"version": "11.0.5",
"resolved": "https://registry.npmjs.org/unified/-/unified-11.0.5.tgz",

View File

@ -14,6 +14,7 @@
"@tailwindcss/typography": "^0.5.15",
"@tailwindcss/vite": "^4.0.0",
"@tsconfig/svelte": "^5.0.4",
"@types/node": "^22.13.9",
"flowbite": "^3.1.2",
"flowbite-svelte": "^0.48.4",
"flowbite-svelte-icons": "^2.0.2",

View File

@ -1,8 +1,10 @@
import { defineConfig } from "vite";
import { defineConfig, loadEnv } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import routify from "@roxi/routify/vite-plugin";
import tailwindcss from "@tailwindcss/vite";
const env = loadEnv(process.env.NODE_ENV as string, process.cwd(), "VITE_");
export default defineConfig({
plugins: [
routify({
@ -15,11 +17,11 @@ export default defineConfig({
host: true,
proxy: {
"/api": {
target: "http://10.10.39.145:3000",
target: env.VITE_BACKEND_URL || "http://localhost:3000",
changeOrigin: true,
},
"/socket.io": {
target: "http://10.10.39.145:3000",
target: env.VITE_BACKEND_URL || "http://localhost:3000",
ws: true,
changeOrigin: true,
},