Cоlе
01/15/2022, 10:20 PMCоlе
01/15/2022, 10:21 PMCоlе
01/15/2022, 10:21 PMGreg Brimble | Cloudflare Pages
01/15/2022, 10:21 PMCоlе
01/15/2022, 10:21 PMitsmatteomanf
01/15/2022, 11:29 PMmike.pete
01/16/2022, 3:03 AMGary Somerhalder
01/16/2022, 3:37 AMHardAtWork
01/16/2022, 3:37 AMmike.pete
01/16/2022, 3:38 AMHardAtWork
01/16/2022, 3:38 AMGary Somerhalder
01/16/2022, 3:38 AMmike.pete
01/16/2022, 3:39 AMmike.pete
01/16/2022, 3:41 AMHardAtWork
01/16/2022, 3:41 AMmike.pete
01/16/2022, 3:42 AMmonolith Apollo GraphQL Server
mike.pete
01/16/2022, 3:43 AMHardAtWork
01/16/2022, 3:43 AMCоlе
01/16/2022, 6:18 AMCоlе
01/16/2022, 6:19 AMcache.match()
on local, and 1101 errors on prodCоlе
01/16/2022, 6:19 AMGreg Brimble | Cloudflare Pages
01/16/2022, 11:26 AMGreg Brimble | Cloudflare Pages
01/16/2022, 11:28 AMfunctions
directory, or with the _worker.js
as mentioned below. I’d personally only go with _worker.js
if you’ve got a custom build process that you need.mike.pete
01/16/2022, 4:07 PMCоlе
01/16/2022, 5:43 PMjs
let hash = await sha256(body)
let url = new URL(request.url)
url.pathname = "/posts" + url.pathname + hash
Is the hashing part required?Cоlе
01/16/2022, 5:43 PMCоlе
01/17/2022, 1:15 AMCоlе
01/17/2022, 1:15 AMts
export const onRequestGet: PagesFunction<{}> = async ({ request, env }): Promise<Response> => {
const doc = "getKits";
const subject = "MJ00Y";
cache = cache || await caches.open('kits');
const cacheKey = new Request(request.url, {
headers: request.headers,
method: 'GET'
});
const cached = await cache.match(request);
if (cached) {
const cloned = cached.clone();
cloned.headers.set('cf-cache-status', 'HIT');
return cloned;
}
let real = GetMongoDocument(env, collectionName, { _id: query(subject!) }).then(async (res) => {
const response = toJSON(res);
cache.put(cacheKey, response.clone());
response.headers.set('cf-cache-status', 'MISS');
return response;
}).catch((err) => {
return toError(Errors.ERR_INTERNAL_ERROR, doc, err);
});
return real;
};
Cоlе
01/17/2022, 1:17 AMJames
01/17/2022, 1:22 AMwaitUntil
the cache.put
to ensure it actually runs, since it returns a promise. It’s available like request and env with functions.