Skip to content

Commit

Permalink
Allow fetching grapher configs from all origins (#4137)
Browse files Browse the repository at this point in the history
Fixes an error when we try to load grapher configs for multi-dim preview
in admin in prod, which runs on a different domain (admin.owid.io) than
the Cloudflare Pages function (ourworldindata.org).
  • Loading branch information
rakyi authored Nov 11, 2024
1 parent b6436c6 commit a22452e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions functions/grapher/by-uuid/[uuid].ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Env, extensions } from "../../_common/env.js"
import { fetchGrapherConfig } from "../../_common/grapherTools.js"
import { IRequestStrict, Router, error, StatusError } from "itty-router"
import { IRequestStrict, Router, error, StatusError, cors } from "itty-router"
import { handleThumbnailRequest } from "../../_common/reusableHandlers.js"

const router = Router<IRequestStrict, [URL, Env, string]>()
const { preflight, corsify } = cors({
allowMethods: ["GET", "OPTIONS", "HEAD"],
})

const router = Router<IRequestStrict, [URL, Env, string]>({
before: [preflight],
finally: [corsify],
})

router
.get(
`/grapher/by-uuid/:uuid${extensions.configJson}`,
Expand Down

0 comments on commit a22452e

Please sign in to comment.