Dough Git

commit

Update cors.ts

commit
597c0d443f7f1a586fb44d72ba00c2cd6b7d019a
author
Clove Twilight <[email protected]>
date
2026-10-01 06:43

diff --git a/src/cors.ts b/src/cors.ts
index 1fcc0a8..5911370 100644
--- a/src/cors.ts
+++ b/src/cors.ts
@@ -20,21 +20,26 @@ const ALLOWED: string[] = [
   "is-a.dev"
 ];
 
-// Exact origins for local development (scheme + host + port must match)
-const DEV_ORIGINS: string[] = [
-  "http://localhost",
-  "http://127.0.0.1",
-];
 
 function isAllowed(origin: string): boolean {
-  if (DEV_ORIGINS.includes(origin)) return true;
+  let url: URL;
 
-  let host: string;
   try {
-    host = new URL(origin).hostname.toLowerCase();
+    url = new URL(origin);
   } catch {
     return false;
   }
+
+  const host = url.hostname.toLowerCase();
+
+  // Local development: allow any port on localhost / 127.0.0.1
+  if (
+    url.protocol === "http:" &&
+    (host === "localhost" || host === "127.0.0.1")
+  ) {
+    return true;
+  }
+
   return ALLOWED.some(
     (domain) => host === domain || host.endsWith("." + domain),
   );