* fix error on port frontend variable .env

* ✨ (constants.ts, vite.config.mts): add support for configurable LANGFLOW_HOST environment variable to allow dynamic backend URL configuration

* 🔧 (constants.ts, vite.config.mts): consolidate backend URL configuration into a single environment variable
This commit is contained in:
Cristhian Zanforlin Lousa 2024-06-21 17:26:58 -03:00 • committed by GitHub
commit 74b8b98cb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 31 deletions

View file

@ -1,32 +1,43 @@
import react from "@vitejs/plugin-react-swc";
import dotenv from "dotenv";
import path from "path";
import { defineConfig } from "vite";
import svgr from "vite-plugin-svgr";
const apiRoutes = ["^/api/v1/", "/health"];
// Use environment variable to determine the target.
const target = process.env.VITE_PROXY_TARGET || "http://127.0.0.1:7860";
export default defineConfig(({ mode }) => {
dotenv.config({ path: path.resolve(__dirname, "../../.env") });
// Use environment variable to determine the UI server port
const port = Number(process.env.VITE_PORT) || 3000;
const apiRoutes = ["^/api/v1/", "/health"];
const proxyTargets = apiRoutes.reduce((proxyObj, route) => {
proxyObj[route] = {
target: target,
changeOrigin: true,
secure: false,
ws: true,
};
return proxyObj;
}, {});
export default defineConfig({
build: {
outDir: "build",
},
plugins: [react(), svgr()],
server: {
port: port,
proxy: {
...proxyTargets,
// Use environment variable to determine the target.
const target = process.env.VITE_PROXY_TARGET || "http://127.0.0.1:7860";
// Use environment variable to determine the UI server port
const port = Number(process.env.VITE_PORT) || 3002;
const proxyTargets = apiRoutes.reduce((proxyObj, route) => {
proxyObj[route] = {
target: target,
changeOrigin: true,
secure: false,
ws: true,
};
return proxyObj;
}, {});
return {
build: {
outDir: "build",
},
},
define: {
"process.env.BACKEND_URL": JSON.stringify(process.env.BACKEND_URL),
},
plugins: [react(), svgr()],
server: {
port: port,
proxy: {
...proxyTargets,
},
},
};
});