File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ const ALLOWED_ORIGIN = process.env.VERCEL_URL
2222 ? `https://${ process . env . VERCEL_URL } `
2323 : "http://localhost:3000"
2424
25+ function isSameOrigin ( origin : string , allowedOrigin : string ) : boolean {
26+ return (
27+ origin . replace ( / \/ \/ w w w \. / , "" ) === allowedOrigin . replace ( / \/ \/ w w w \. / , "" )
28+ )
29+ }
30+
2531export async function GET ( request : NextRequest ) {
2632 let origin = request . headers . get ( "origin" )
2733 if ( ! origin ) {
@@ -30,8 +36,9 @@ export async function GET(request: NextRequest) {
3036
3137 const headers = new Headers ( {
3238 "Content-Type" : "application/json" ,
33- "Access-Control-Allow-Origin" :
34- origin === PRODUCTION_ORIGIN ? PRODUCTION_ORIGIN : ALLOWED_ORIGIN ,
39+ "Access-Control-Allow-Origin" : isSameOrigin ( origin , PRODUCTION_ORIGIN )
40+ ? PRODUCTION_ORIGIN
41+ : ALLOWED_ORIGIN ,
3542 "Access-Control-Allow-Methods" : "GET" ,
3643 "Access-Control-Allow-Headers" : "Content-Type" ,
3744 "Cache-Control" : "public, s-maxage=86400, stale-while-revalidate=172800" ,
You can’t perform that action at this time.
0 commit comments