Skip to content

Commit c8c351d

Browse files
committed
Handle production origin
1 parent e3f035e commit c8c351d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/app/api/contributors/route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ function getContributorData(): ContributorData {
1717
return contributorData as ContributorData
1818
}
1919

20+
const PRODUCTION_ORIGIN = `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
2021
const ALLOWED_ORIGIN = process.env.VERCEL_URL
2122
? `https://${process.env.VERCEL_URL}`
2223
: "http://localhost:3000"
2324

2425
export async function GET(request: NextRequest) {
26+
let origin = request.headers.get("origin")
27+
if (!origin) {
28+
origin = (request.headers.get("referer") || "").replace(/\/$/, "")
29+
}
30+
2531
const headers = new Headers({
2632
"Content-Type": "application/json",
27-
"Access-Control-Allow-Origin": ALLOWED_ORIGIN,
33+
"Access-Control-Allow-Origin":
34+
origin === PRODUCTION_ORIGIN ? PRODUCTION_ORIGIN : ALLOWED_ORIGIN,
2835
"Access-Control-Allow-Methods": "GET",
2936
"Access-Control-Allow-Headers": "Content-Type",
3037
"Cache-Control": "public, s-maxage=86400, stale-while-revalidate=172800",

src/components/index-page/how-it-works/schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ const ProjectType = new GraphQLObjectType<Project>({
109109
if (args.after) params.set("after", args.after)
110110
params.set("project", project.name)
111111

112-
const response = await fetch(`/api/contributors?${params.toString()}`)
112+
const response = await fetch(
113+
`/api/contributors/?${params.toString()}`,
114+
)
113115

114116
if (!response.ok) {
115117
console.error(`Failed to fetch contributors: ${response.status}`)

0 commit comments

Comments
 (0)