import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueDevTools from 'vite-plugin-vue-devtools' // Backend service base URL - uses container names when running in container, localhost otherwise // In container: services communicate via podman network using service names // Native: services are accessed via localhost with mapped ports const BACKEND_HOST = process.env.CONTAINER_MODE === 'true' ? 'host.containers.internal' : 'localhost' // https://vite.dev/config/ export default defineConfig({ plugins: [ vue(), vueDevTools() ], server: { port: 5173, // Development mode host: '0.0.0.0', // Listen on all interfaces for container access proxy: { '/api/auth': { target: `http://${BACKEND_HOST}:8082`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/auth/, '') }, '/api/work': { target: `http://${BACKEND_HOST}:8083`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/work/, '') }, '/api/payment': { target: `http://${BACKEND_HOST}:8084`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/payment/, '') }, '/api/blog': { target: `http://${BACKEND_HOST}:8085`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/blog/, '') }, '/api/ipfs': { target: `http://${BACKEND_HOST}:8086`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/ipfs/, '') }, '/api/llm': { target: `http://${BACKEND_HOST}:8087`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/llm/, '') }, '/api/contact': { target: `http://${BACKEND_HOST}:8088`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/contact/, '') }, '/api/forum': { target: `http://${BACKEND_HOST}:8089`, changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/forum/, '') } } }, resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), // Polyfills for P2P libraries (Helia/OrbitDB) buffer: 'buffer/', stream: 'stream-browserify', util: 'util/', process: 'process/browser', events: 'events/' }, }, define: { 'global': 'globalThis', 'process.env': {} }, optimizeDeps: { include: ['buffer', 'process'], esbuildOptions: { target: 'esnext' } }, build: { target: 'esnext', rollupOptions: { // Mark P2P modules as external if they cause issues // These will be dynamically imported at runtime } } })