fix(frontend/vite): Configure vite dev proxy to handle frontend path
This commit is contained in:
parent
7710e2549e
commit
57e2a33dc6
|
|
@ -269,16 +269,25 @@ function getBuildConfig(env: Record<string, string>) {
|
||||||
function getServeConfig(env: Record<string, string>) {
|
function getServeConfig(env: Record<string, string>) {
|
||||||
// get some default settings from prod mod
|
// get some default settings from prod mod
|
||||||
const buildConfig = getBuildConfig(env)
|
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
|
// override prod settings with dev settings
|
||||||
return {
|
return {
|
||||||
...buildConfig,
|
...buildConfig,
|
||||||
server: {
|
server: {
|
||||||
...buildConfig.server,
|
...buildConfig.server,
|
||||||
...(env.DEV_PROXY && { proxy: {
|
...(env.DEV_PROXY && { proxy: {
|
||||||
'/api': {
|
[proxyPath]: {
|
||||||
target: env.DEV_PROXY,
|
target: env.DEV_PROXY,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
|
// Strips prefix for the backend
|
||||||
|
rewrite: (path: string) => path.replace(new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), ''),
|
||||||
},
|
},
|
||||||
}}),
|
}}),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue