Skip to content

Commit b259009

Browse files
conico974Nicolas Dorseuil
and
Nicolas Dorseuil
authored
Add temporary logging for Cloudflare debugging (#3249)
Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
1 parent d88dd5e commit b259009

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/gitbook-v2/wrangler.jsonc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@
9393
"vars": {
9494
// This is a bit misleading, but it means that we can have 500 concurrent revalidations
9595
// This means that we'll have up to 100 durable objects instance running at the same time
96-
"MAX_REVALIDATE_CONCURRENCY": "100"
96+
"MAX_REVALIDATE_CONCURRENCY": "100",
97+
// Temporary variable to find the issue once deployed
98+
// TODO: remove this once the issue is fixed
99+
"DEBUG_CLOUDFLARE": "true"
97100
},
98101
"routes": [
99102
{

packages/gitbook/src/routes/ogimage.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,25 @@ async function loadCustomFont(input: { url: string; weight: 400 | 700 }) {
311311
};
312312
}
313313

314+
/**
315+
* Temporary function to log some data on Cloudflare.
316+
* TODO: remove this when we found the issue
317+
*/
318+
function logOnCloudflareOnly(message: string) {
319+
if (process.env.DEBUG_CLOUDFLARE === 'true') {
320+
// biome-ignore lint/suspicious/noConsole: <explanation>
321+
console.log(message);
322+
}
323+
}
324+
314325
/**
315326
* Fetch a resource from the function itself.
316327
* To avoid error with worker to worker requests in the same zone, we use the `WORKER_SELF_REFERENCE` binding.
317328
*/
318329
async function fetchSelf(url: string) {
319330
const cloudflare = getCloudflareContext();
320331
if (cloudflare?.env.WORKER_SELF_REFERENCE) {
332+
logOnCloudflareOnly(`Fetching self: ${url}`);
321333
return await cloudflare.env.WORKER_SELF_REFERENCE.fetch(
322334
// `getAssetURL` can return a relative URL, so we need to make it absolute
323335
// the URL doesn't matter, as we're using the worker-self-reference binding
@@ -334,6 +346,9 @@ async function fetchSelf(url: string) {
334346
async function readImage(response: Response) {
335347
const contentType = response.headers.get('content-type');
336348
if (!contentType || !contentType.startsWith('image/')) {
349+
logOnCloudflareOnly(`Invalid content type: ${contentType},
350+
status: ${response.status}
351+
rayId: ${response.headers.get('cf-ray')}`);
337352
throw new Error(`Invalid content type: ${contentType}`);
338353
}
339354

0 commit comments

Comments
 (0)