Merge pull request #400 from goteo/feat/disable-cache-interceptor
feat/disable-cache-interceptor
This commit is contained in:
@@ -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`
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user