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
22
22
? `https://${ process . env . VERCEL_URL } `
23
23
: "http://localhost:3000"
24
24
25
+ function isSameOrigin ( origin : string , allowedOrigin : string ) : boolean {
26
+ return (
27
+ origin . replace ( / \/ \/ w w w \. / , "" ) === allowedOrigin . replace ( / \/ \/ w w w \. / , "" )
28
+ )
29
+ }
30
+
25
31
export async function GET ( request : NextRequest ) {
26
32
let origin = request . headers . get ( "origin" )
27
33
if ( ! origin ) {
@@ -30,8 +36,9 @@ export async function GET(request: NextRequest) {
30
36
31
37
const headers = new Headers ( {
32
38
"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 ,
35
42
"Access-Control-Allow-Methods" : "GET" ,
36
43
"Access-Control-Allow-Headers" : "Content-Type" ,
37
44
"Cache-Control" : "public, s-maxage=86400, stale-while-revalidate=172800" ,
You can’t perform that action at this time.
0 commit comments