fix(frontend): Interceptor normalisiert ALLE apiClient-URLs — auch Direktaufrufe und Cache-Alte-Chunks
Der apiX-Wrapper-Fix (744f2a1) heilte nur Wrapper-Aufrufe. Produktion-Logs
zeigten: POST /api/v1/api/v1/ai-proactive/context → 405 (4x vom User-
Browser mit alten gecachten Chunks). Der Request-Interceptor strippt jetzt
redundante /api/v1-Präfixe auf Transport-Ebene — heilt auch Direkt-
apiClient-Calls und stale Cache-Artefakte transparent.
This commit is contained in:
@@ -47,6 +47,16 @@ export function setValidationErrorHandler(handler: (errors: Record<string, strin
|
|||||||
|
|
||||||
apiClient.interceptors.request.use(
|
apiClient.interceptors.request.use(
|
||||||
(config: InternalAxiosRequestConfig) => {
|
(config: InternalAxiosRequestConfig) => {
|
||||||
|
// Normalize URLs: strip a redundant leading '/api/v1' when it collides
|
||||||
|
// with the axios baseURL '/api/v1' (double-prefix → 404/405). Done here
|
||||||
|
// in the interceptor (not only in the apiX wrappers) so DIRECT apiClient
|
||||||
|
// calls are covered too — stale browser-cache chunks keep calling with
|
||||||
|
// full prefixes after deploys and this heals them transparently.
|
||||||
|
if (typeof config.url === 'string' && config.url.startsWith('/api/v1/')) {
|
||||||
|
config.url = config.url.slice('/api/v1'.length);
|
||||||
|
} else if (config.url === '/api/v1') {
|
||||||
|
config.url = '/';
|
||||||
|
}
|
||||||
// Attach CSRF token on unsafe methods
|
// Attach CSRF token on unsafe methods
|
||||||
const unsafe = ['post', 'put', 'patch', 'delete'];
|
const unsafe = ['post', 'put', 'patch', 'delete'];
|
||||||
if (unsafe.includes(config.method?.toLowerCase() ?? '') && csrfToken) {
|
if (unsafe.includes(config.method?.toLowerCase() ?? '') && csrfToken) {
|
||||||
|
|||||||
Reference in New Issue
Block a user