Skip to content

Commit

Permalink
🔨 add debugging facility
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Aug 12, 2024
1 parent 6de72ac commit 5f7e06e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion functions/grapher/thumbnail/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@ export interface Env {
fetch: typeof fetch
}
url: URL
ENV: string
}

const router = Router<IRequestStrict, [URL, Env, ExecutionContext]>()
router
.get(
"/grapher/thumbnail/_debug",
async ({ params: {} }, { searchParams }, env) => {
console.log("Constructing debug info")
const info = {
url: env.url,
env: env.ENV,
searchParams: Array.from(searchParams.entries()),
}
return new Response(JSON.stringify(info), {
headers: { "Content-Type": "application/json" },
})
}
)
.get(
"/grapher/thumbnail/:slug.png",
async ({ params: { slug } }, { searchParams }, env) =>
Expand Down Expand Up @@ -39,7 +54,11 @@ export const onRequestGet: PagesFunction = async (ctx) => {
if (maybeCached) return maybeCached
}

console.log("Handling", request.url, request.headers.get("User-Agent"))
console.log(
"Handling (with debug support)",
request.url,
request.headers.get("User-Agent")
)

return router
.fetch(request, url, { ...env, url }, ctx)
Expand Down
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV = "development"
[env.preview.vars]
MAILGUN_DOMAIN = "mg.ourworldindata.org"
SLACK_ERROR_CHANNEL_ID = "C016H0BNNB1"

ENV = "preview"

# Overrides for CF production deployment
[env.production]
Expand Down

0 comments on commit 5f7e06e

Please sign in to comment.