@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server"
22import contributorData from "../../../../scripts/sync-landing-schema/data.json"
33
44export const dynamic = "auto"
5+ export const revalidate = 172800
56
67interface Contributor {
78 id : string
@@ -17,31 +18,22 @@ function getContributorData(): ContributorData {
1718 return contributorData as ContributorData
1819}
1920
20- const PRODUCTION_ORIGIN = `https://${ process . env . VERCEL_PROJECT_PRODUCTION_URL } `
21- const ALLOWED_ORIGIN = process . env . VERCEL_URL
22- ? `https://${ process . env . VERCEL_URL } `
23- : "http://localhost:3000"
24-
25- function isSameOrigin ( origin : string , allowedOrigin : string ) : boolean {
26- return (
27- origin . replace ( / \/ \/ w w w \. / , "" ) === allowedOrigin . replace ( / \/ \/ w w w \. / , "" )
28- )
29- }
21+ const ALLOWED_ORIGIN =
22+ process . env . VERCEL_ENV === "production"
23+ ? `https://${ process . env . VERCEL_PROJECT_PRODUCTION_URL } `
24+ : process . env . VERCEL_URL
25+ ? `https://${ process . env . VERCEL_URL } `
26+ : "http://localhost:3000"
3027
3128export async function GET ( request : NextRequest ) {
32- let origin = request . headers . get ( "origin" )
33- if ( ! origin ) {
34- origin = ( request . headers . get ( "referer" ) || "" ) . replace ( / \/ $ / , "" )
35- }
29+ const origin = request . headers . get ( "origin" )
3630
3731 const headers = new Headers ( {
3832 "Content-Type" : "application/json" ,
39- "Access-Control-Allow-Origin" : isSameOrigin ( origin , PRODUCTION_ORIGIN )
40- ? PRODUCTION_ORIGIN
41- : ALLOWED_ORIGIN ,
33+ "Access-Control-Allow-Origin" : ALLOWED_ORIGIN ,
4234 "Access-Control-Allow-Methods" : "GET" ,
4335 "Access-Control-Allow-Headers" : "Content-Type" ,
44- "Cache-Control" : " public, s-maxage=86400, stale-while-revalidate=172800" ,
36+ "Cache-Control" : ` public, s-maxage=86400, stale-while-revalidate=${ revalidate } ` ,
4537 } )
4638
4739 try {
0 commit comments