Files
assetsTracker/vite.config.js
2026-04-02 15:56:03 +02:00

55 lines
1.5 KiB
JavaScript

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
/** Ziel der Appwrite-API für den Dev-Proxy /v1 → … (wenn Client VITE_APPWRITE_ENDPOINT=http://localhost:5173/v1 nutzt) */
function resolveAppwriteProxyTarget(env) {
const explicit = (env.VITE_APPWRITE_PROXY_TARGET || '').trim().replace(/\/$/, '')
if (explicit) return explicit
const ep = (env.VITE_APPWRITE_ENDPOINT || '').trim()
if (!ep) return 'https://appwrite.webklar.com'
try {
const u = new URL(ep)
if (u.hostname === 'localhost' || u.hostname === '127.0.0.1') {
return 'https://appwrite.webklar.com'
}
return u.origin
} catch {
return 'https://appwrite.webklar.com'
}
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const proxyTarget = resolveAppwriteProxyTarget(env)
return {
plugins: [react(), tailwindcss()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
proxy: {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true,
},
'/v1': {
target: proxyTarget,
changeOrigin: true,
secure: true,
timeout: 120_000,
proxyTimeout: 120_000,
},
},
},
}
})