fix(frontend/vite): Configure vite dev proxy to handle frontend path

This commit is contained in:
MidoriKurage 2026-03-21 21:34:51 +08:00 committed by kolaente
parent 7710e2549e
commit 57e2a33dc6
1 changed files with 10 additions and 1 deletions

View File

@ -269,16 +269,25 @@ function getBuildConfig(env: Record<string, string>) {
function getServeConfig(env: Record<string, string>) {
// get some default settings from prod mod
const buildConfig = getBuildConfig(env)
// Build the proxy pattern from VIKUNJA_FRONTEND_BASE so that custom base
// paths like /vikunja proxy /vikunja/api/* correctly.
// Falls back to /api.
const base = (env.VIKUNJA_FRONTEND_BASE || '/').replace(/\/+$/, '')
const proxyPath = `${base}/api`
// override prod settings with dev settings
return {
...buildConfig,
server: {
...buildConfig.server,
...(env.DEV_PROXY && { proxy: {
'/api': {
[proxyPath]: {
target: env.DEV_PROXY,
changeOrigin: true,
secure: false,
// Strips prefix for the backend
rewrite: (path: string) => path.replace(new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), ''),
},
}}),
},