Skip to content

Commit

Permalink
🔨 incorporate PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Aug 21, 2024
1 parent 1cdc3b3 commit 67a25ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
20 changes: 7 additions & 13 deletions functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -263,8 +258,7 @@ export const fetchAndRenderGrapher = async (
slug,
options,
searchParams,
env,
etag
env
)
console.log("fetched svg")

Expand Down

0 comments on commit 67a25ef

Please sign in to comment.