fix: update frontend API key handling and improve export documentation

This commit is contained in:
Alexis
2026-05-19 09:52:50 +02:00
parent 8d29fb054d
commit 59eda988d2
8 changed files with 79 additions and 42 deletions
+18 -6
View File
@@ -6,6 +6,19 @@ export default defineConfig(({ mode }) => {
const env = loadEnv(mode, import.meta.dirname, '')
const proxyTarget = env.VITE_API_PROXY_TARGET || 'http://localhost:8000'
const base = env.VITE_BASE_PATH || '/'
const proxyApiKey = env.API_KEY_VALUE || env.VITE_API_KEY || ''
const proxyCommon = {
target: proxyTarget,
changeOrigin: true,
...(proxyApiKey && {
configure: (proxy) => {
proxy.on('proxyReq', (proxyReq) => {
proxyReq.setHeader('X-API-Key', proxyApiKey)
})
},
}),
}
return {
base,
@@ -15,16 +28,15 @@ export default defineConfig(({ mode }) => {
allowedHosts: true,
port: 5173,
proxy: {
'/api': { target: proxyTarget, changeOrigin: true },
'/api': proxyCommon,
'/health': { target: proxyTarget, changeOrigin: true },
...(base !== '/' && {
[`${base}api`]: {
target: proxyTarget,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${base}api`), '/api')
}
...proxyCommon,
rewrite: (path) => path.replace(new RegExp(`^${base}api`), '/api'),
},
}),
},
},
}
})
})