From f645f610c0a6c61ee59407a40f156d9d99681daa Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 12 Jun 2024 19:43:01 -0700 Subject: [PATCH] Clean origin response to allow custom cache logic --- functions/api.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/api.js b/functions/api.js index a9c4e61..dfbbff4 100644 --- a/functions/api.js +++ b/functions/api.js @@ -10,7 +10,9 @@ export async function onRequestGet({ request, env, waitUntil }) { } const token = await getGoogleAuthToken(env.EMAIL, env.PRIVATE_KEY, 'https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/documents.readonly'); - const responsePromise = fetch(queryUrl, { headers: { Authorization: `Bearer ${token}` } }); + const responsePromise = fetch(queryUrl, { headers: { Authorization: `Bearer ${token}` } }) + .then(r => r.blob()) + .then(b => new Response(b, { headers: { 'Content-Type': 'application/json' } })); // Remove extra response headers which may interfere with cache const cachedResponse = await caches.default.match(queryUrl); if (cachedResponse) { waitUntil(responsePromise.then(response => caches.default.put(queryUrl, response))); -- 2.47.3