import { tanstackStart } from "@tanstack/react-start/plugin/vite"; import { defineConfig, loadEnv } from "vite"; import tsConfigPaths from "vite-tsconfig-paths"; import viteReact from "@vitejs/plugin-react"; import tailwindcss from "@tailwindcss/vite"; import { cloudflare } from "@cloudflare/vite-plugin"; import { devtools } from "@tanstack/devtools-vite"; import { leanWorkerBundle } from "./vite-plugin-lean-worker-bundle"; export default defineConfig(({ mode }) => { // PORT/ALLOWED_HOST are documented self-host knobs (SELF_HOSTING_DOCKER.md, // compose.yaml) but were never actually read here — every deployment was // silently stuck on port 3001 and this one hardcoded domain, breaking any // second instance on a different domain or port. Defaults keep existing // deployments that don't set these working exactly as before. // // Read via Vite's own loadEnv(), not bare process.env: process.env inside // this config function only sees whatever the OS process environment // already has (e.g. exported by the shell or pm2's ecosystem file) — // Vite's .env-file loading (envPrefix below) only reaches import.meta.env // in app code, not this function. loadEnv reads the same .env files Vite // always has, regardless of how the process was launched. const env = loadEnv(mode, process.cwd(), ""); const port = Number(env.PORT) || 3001; const showDevtools = false; const allowedHosts = [ "seo.thedomainnest.com", env.ALLOWED_HOST, ].filter((host): host is string => Boolean(host)); return { envPrefix: [ "VITE_", "AUTH_MODE", "BYPASS_EMAIL_VERIFICATION", "POSTHOG_PUBLIC_KEY", "POSTHOG_HOST", "TURNSTILE_SITE_KEY", "GOOGLE_CLIENT_ID", ], server: { host: "0.0.0.0", port, allowedHosts, }, preview: { host: "0.0.0.0", port, allowedHosts, }, build: { sourcemap: false, outDir: "dist", }, plugins: [ leanWorkerBundle(), showDevtools ? devtools({ consolePiping: { enabled: true, levels: ["log", "warn", "error", "info", "debug"], }, }) : null, cloudflare({ inspectorPort: false, viteEnvironment: { name: "ssr" }, auxiliaryWorkers: [ { configPath: "./wrangler.audit.jsonc", }, ], }), tsConfigPaths(), tanstackStart(), viteReact(), tailwindcss(), ], }; });