24 lines
1007 B
TypeScript
24 lines
1007 B
TypeScript
import react from '@vitejs/plugin-react'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
|
|
// 开发时把 /api 转发给后端,地址取自环境变量 BACKEND_URL,或 web/.env.local 里的 BACKEND_URL=(见 web/.env.example):
|
|
// BACKEND_URL=https://mo.oeo.one npm run dev:display
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, fileURLToPath(new URL('..', import.meta.url)), '')
|
|
const backend = (process.env.BACKEND_URL ?? env.BACKEND_URL ?? 'http://localhost:5000').replace(/\/+$/, '')
|
|
return {
|
|
base: '/admin/',
|
|
plugins: [react()],
|
|
resolve: { alias: { '@shared': fileURLToPath(new URL('../shared', import.meta.url)) } },
|
|
server: {
|
|
port: 5174,
|
|
fs: { allow: ['..'] },
|
|
proxy: {
|
|
'/api': { target: backend, changeOrigin: true, secure: true, cookieDomainRewrite: '' },
|
|
'/healthz': { target: backend, changeOrigin: true, secure: true, cookieDomainRewrite: '' },
|
|
},
|
|
},
|
|
}
|
|
})
|