diff --git a/functions/README.md b/functions/README.md index 6fdf5ca8bf4..42219c564b4 100644 --- a/functions/README.md +++ b/functions/README.md @@ -28,7 +28,7 @@ Note: compatibility dates between local development, production and preview envi 3. _Refer to each function's "Development" section below for further instructions._ -## Testing on Fondation staging sites vs Cloudfare previews +## Testing on Foundation staging sites vs Cloudflare previews We have two cloudflare projects set up that you can deploy previews to. `owid` which is also where our production deployment runs, and `owid-staging`. Currently, `owid` is configured to require authentication while `owid-staging` is accessible from the internet without any kind of auth. diff --git a/functions/_common/grapherRenderer.ts b/functions/_common/grapherRenderer.ts index b18a5551b30..f189d2b6329 100644 --- a/functions/_common/grapherRenderer.ts +++ b/functions/_common/grapherRenderer.ts @@ -162,14 +162,10 @@ async function fetchAndRenderGrapherToSvg( slug: string, options: ImageOptions, searchParams: URLSearchParams, - env: Env, - etag?: string + env: Env ) { const grapherLogger = new TimeLogger("grapher") - const url = new URL(`/grapher/${slug}`, env.url) - const slugOnly = url.pathname.split("/").pop() - // The top level directory is either the bucket path (should be set in dev environments and production) // or the branch name on preview staging environments console.log("branch", env.CF_PAGES_BRANCH) @@ -180,7 +176,7 @@ async function fetchAndRenderGrapherToSvg( const key = excludeUndefined([ ...topLevelDirectory, R2GrapherConfigDirectory.publishedGrapherBySlug, - `${slugOnly}.json`, + `${slug}.json`, ]).join("/") console.log("fetching grapher config from this key", key) @@ -195,9 +191,9 @@ async function fetchAndRenderGrapherToSvg( ) { const topLevelDirectory = env.GRAPHER_CONFIG_R2_BUCKET_FALLBACK_PATH const fallbackKey = excludeUndefined([ - ...topLevelDirectory, + topLevelDirectory, R2GrapherConfigDirectory.publishedGrapherBySlug, - `${slugOnly}.json`, + `${slug}.json`, ]).join("/") fallbackUrl = new URL( fallbackKey, @@ -206,7 +202,7 @@ async function fetchAndRenderGrapherToSvg( } // Fetch grapher config - const fetchResponse = await fetchFromR2(requestUrl, etag, fallbackUrl) + const fetchResponse = await fetchFromR2(requestUrl, undefined, fallbackUrl) if (fetchResponse.status !== 200) { console.log("Failed to fetch grapher config", fetchResponse.status) @@ -253,8 +249,7 @@ export const fetchAndRenderGrapher = async ( slug: string, searchParams: URLSearchParams, outType: "png" | "svg", - env: Env, - etag?: string + env: Env ) => { const options = extractOptions(searchParams) @@ -263,8 +258,7 @@ export const fetchAndRenderGrapher = async ( slug, options, searchParams, - env, - etag + env ) console.log("fetched svg")