Merge pull request #400 from goteo/feat/disable-cache-interceptor

feat/disable-cache-interceptor
This commit is contained in:
2026-08-07 16:45:39 +02:00
committed by GitHub
3 changed files with 9 additions and 0 deletions
+3
View File
@@ -3,6 +3,9 @@
PUBLIC_API_URL=""
PUBLIC_API_VERSION="v4"
# Disable API browser cache interceptor globally (true for local development)
PUBLIC_DISABLE_CACHE=false
# OAuth
# An OAuth client must exist for this web app in the v4 API instance
# The client should allow the grants: `authorization_code`, `refresh_token`, `password`
+3
View File
@@ -53,6 +53,9 @@ function isStaleCache(cached: Response, defaultMaxAgeMs: number = DEFAULT_MAX_AG
export function createBrowserCacheInterceptor(cacheName: string = CACHE_NAME) {
return async (request: Request, opts: RequestOptions): Promise<Request> => {
if (import.meta.env.PUBLIC_DISABLE_CACHE === "true") {
return request;
}
const originalFetch = opts.fetch ?? globalThis.fetch;
opts.fetch = async (req: Request) => {
+3
View File
@@ -13,6 +13,9 @@ export function getCacheInterceptorId() {
}
export function initCacheInterceptor() {
if (import.meta.env.PUBLIC_DISABLE_CACHE === "true") {
return null;
}
_interceptor = createBrowserCacheInterceptor();
_interceptorId = client.interceptors.request.use(_interceptor);
return _interceptorId;