Skip to content

Commit

Permalink
fix(www): cors headers
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Dec 19, 2024
1 parent 57096c1 commit 8de3d7a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions www/api/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export default async function (request: Request) {
if (request.method !== "POST") {
return new Response(StatusText[Status.MethodNotAllowed], { status: Status.MethodNotAllowed, headers })
}
if (!allowed.includes(new URL(`https://${request.headers.get("Host")}`).hostname)) {
return new Response("Custom builds may not be linked directly", { status: Status.Forbidden, headers })
if ((request.headers.has("Origin")) && (allowed.includes(new URL(request.headers.get("Origin")!).hostname))) {
headers.set("Access-Control-Allow-Origin", "*")
headers.set("Access-Control-Allow-Methods", "GET, POST")
headers.set("Access-Control-Allow-Headers", "Content-Type")
} else {
return new Response(`Visit "${request.headers.get("Origin") ?? "https://mizu.sh"}/build" to download a custom build`, { status: Status.Forbidden, headers })
}
try {
const options = await request.json()
Expand Down

0 comments on commit 8de3d7a

Please sign in to comment.