Skip to content

Commit a358033

Browse files
committed
Strip www. for comparison
1 parent c8c351d commit a358033

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/app/api/contributors/route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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(/\/\/www\./, "") === allowedOrigin.replace(/\/\/www\./, "")
28+
)
29+
}
30+
2531
export 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",

0 commit comments

Comments
 (0)