mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix: apply Biome formatting to docs-proxy (remove semicolons)
The project uses no-semicolons style per Biome configuration. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
fad0553b67
commit
9b85bb2ca4
1 changed files with 23 additions and 20 deletions
|
|
@ -1,33 +1,36 @@
|
|||
const UPSTREAM_BASE = "https://supermemory.mintlify.dev";
|
||||
const CACHE_TTL = 300; // 5 minutes
|
||||
const FETCH_TIMEOUT_MS = 10000; // 10 seconds
|
||||
const UPSTREAM_BASE = "https://supermemory.mintlify.dev"
|
||||
const CACHE_TTL = 300 // 5 minutes
|
||||
const FETCH_TIMEOUT_MS = 10000 // 10 seconds
|
||||
|
||||
export default {
|
||||
async fetch(request: Request): Promise<Response> {
|
||||
const url = new URL(request.url);
|
||||
const proxyUrl = UPSTREAM_BASE + url.pathname + url.search;
|
||||
const url = new URL(request.url)
|
||||
const proxyUrl = UPSTREAM_BASE + url.pathname + url.search
|
||||
|
||||
const cache = caches.default;
|
||||
const cache = caches.default
|
||||
|
||||
if (request.method === "GET") {
|
||||
const cached = await cache.match(request);
|
||||
if (cached) return cached;
|
||||
const cached = await cache.match(request)
|
||||
if (cached) return cached
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
||||
const controller = new AbortController()
|
||||
const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS)
|
||||
|
||||
try {
|
||||
const proxyRequest = new Request(proxyUrl, request);
|
||||
const response = await fetch(proxyRequest, { signal: controller.signal });
|
||||
const proxyRequest = new Request(proxyUrl, request)
|
||||
const response = await fetch(proxyRequest, { signal: controller.signal })
|
||||
|
||||
if (request.method === "GET" && response.ok) {
|
||||
const cachedResponse = new Response(response.clone().body, response);
|
||||
cachedResponse.headers.set("Cache-Control", `public, max-age=${CACHE_TTL}`);
|
||||
await cache.put(request, cachedResponse);
|
||||
const cachedResponse = new Response(response.clone().body, response)
|
||||
cachedResponse.headers.set(
|
||||
"Cache-Control",
|
||||
`public, max-age=${CACHE_TTL}`,
|
||||
)
|
||||
await cache.put(request, cachedResponse)
|
||||
}
|
||||
|
||||
return response;
|
||||
return response
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.name === "AbortError") {
|
||||
return new Response(
|
||||
|
|
@ -36,11 +39,11 @@ export default {
|
|||
status: 504,
|
||||
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
||||
},
|
||||
);
|
||||
)
|
||||
}
|
||||
throw e;
|
||||
throw e
|
||||
} finally {
|
||||
clearTimeout(timeoutId);
|
||||
clearTimeout(timeoutId)
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue