/ client / webui / frontend / vite.config.ts
vite.config.ts
 1  import path from "path";
 2  import fs from "fs";
 3  import tailwindcss from "@tailwindcss/vite";
 4  import react from "@vitejs/plugin-react";
 5  import { defineConfig, loadEnv } from "vite";
 6  
 7  /**
 8   * Local Vite plugin to generate ui-version.json during build.
 9   * This metadata file contains version information that can be read at runtime
10   * without exposing the full package.json.
11   */
12  function generateVersionMetadata() {
13      return {
14          name: "generate-version-metadata",
15          closeBundle() {
16              const packageJsonPath = path.resolve(__dirname, "package.json");
17              const outputPath = path.resolve(__dirname, "static", "ui-version.json");
18  
19              try {
20                  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
21                  const versionMetadata = {
22                      id: packageJson.name,
23                      name: "Solace Agent Mesh UI",
24                      description: packageJson.description || "",
25                      version: packageJson.version,
26                  };
27  
28                  // Ensure output directory exists before writing
29                  const outputDir = path.dirname(outputPath);
30                  if (!fs.existsSync(outputDir)) {
31                      fs.mkdirSync(outputDir, { recursive: true });
32                  }
33  
34                  fs.writeFileSync(outputPath, JSON.stringify(versionMetadata, null, 2) + "\n");
35                  console.log(`Generated ui-version.json: ${versionMetadata.version}`);
36              } catch (error) {
37                  console.error("Failed to generate ui-version.json:", error);
38              }
39          },
40      };
41  }
42  
43  export default defineConfig(({ mode }) => {
44      const env = loadEnv(mode, process.cwd(), "");
45  
46      const backendPort = env.VITE_BACKEND_PORT || process.env.FASTAPI_PORT || "8000";
47      const backendTarget = `http://localhost:${backendPort}`;
48  
49      const platformPort = env.VITE_PLATFORM_PORT || "8001";
50      const platformTarget = `http://localhost:${platformPort}`;
51  
52      return {
53          plugins: [react(), tailwindcss(), generateVersionMetadata()],
54          resolve: {
55              alias: {
56                  "@": path.resolve(__dirname, "./src"),
57              },
58          },
59          build: {
60              outDir: "static",
61              emptyOutDir: true,
62              rollupOptions: {
63                  input: {
64                      main: "index.html",
65                      authCallback: "auth-callback.html",
66                  },
67                  output: {
68                      manualChunks: {
69                          vendor: ["react", "react-dom", "json-edit-react", "marked", "@tanstack/react-table", "lucide-react", "html-react-parser"],
70                      },
71                  },
72              },
73          },
74          server: {
75              proxy: {
76                  // IMPORTANT: Platform Service endpoints must come first for specificity
77                  // More specific routes must be defined before general routes
78                  "/api/v1/platform": {
79                      target: platformTarget,
80                      changeOrigin: true,
81                      secure: false,
82                  },
83                  // Community endpoints - catch-all for remaining /api routes
84                  "/api": {
85                      target: backendTarget,
86                      changeOrigin: true,
87                      secure: false,
88                  },
89              },
90              port: 3000, // Explicitly set frontend dev server port (optional)
91              host: true, // Allow access from network (optional)
92          },
93      };
94  });