import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import tailwindcss from "@tailwindcss/vite";
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
import path from "path";

import dotenv from "dotenv";
import { fileURLToPath } from "url";
dotenv.config({
    path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.env"),
});

// https://vite.dev/config/
export default defineConfig({
    plugins: [
        react(),
        tailwindcss(),
        TanStackRouterVite({ target: "react", autoCodeSplitting: true }),
    ],
    // base: "/lst", // this is whats showing in the ssl version and we need this to work on both versions that also have a port on them.
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "./src"),
        },
    },
    server: {
        proxy: {
            "/api": {
                target: `http://localhost:${Number(process.env.VITE_SERVER_PORT || 4400)}`,
                changeOrigin: true,
                secure: false,
            },
            "/ocme": {
                target: `http://localhost:${Number(process.env.VITE_SERVER_PORT || 4400)}`,
                changeOrigin: true,
                secure: false,
            },
        },
    },
});
