commit
Fixes
diff --git a/src/index.ts b/src/index.ts
index 548d9c3..66f337b 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -471,6 +471,8 @@ export default {
* https). Cloudflare terminates TLS, so we check the URL scheme plus the
* proxy headers that carry the original client scheme. */
function isInsecure(req: Request, url: URL): boolean {
+ // Local dev (wrangler / bun dev) has no TLS — never redirect localhost.
+ if (url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]") return false;
if (url.protocol === "http:") return true;
const xfProto = req.headers.get("x-forwarded-proto");
if (xfProto && xfProto.split(",")[0].trim().toLowerCase() === "http") return true;
diff --git a/src/system/app.ts b/src/system/app.ts
index 955e8bb..556467d 100644
--- a/src/system/app.ts
+++ b/src/system/app.ts
@@ -23,7 +23,7 @@ import { cors } from "hono/cors";
import type { Env } from "./hono";
import { HttpError } from "./errors";
-import { corsOrigins } from "./config";
+import { corsOrigins, isLocalhostOrigin } from "./config";
import { initializeAdminUser } from "./services/users";
import { authRoutes } from "./routes/auth";
@@ -74,7 +74,8 @@ export const systemApp = new Hono<Env>();
systemApp.use(
"*",
cors({
- origin: (origin) => (corsOrigins().includes(origin) ? origin : ""),
+ origin: (origin) =>
+ isLocalhostOrigin(origin) || corsOrigins().includes(origin) ? origin : "",
credentials: true,
allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
}),
diff --git a/src/system/config.ts b/src/system/config.ts
index 9673b21..1d33f37 100644
--- a/src/system/config.ts
+++ b/src/system/config.ts
@@ -61,11 +61,16 @@ export function baseUrl(): string {
return (rt().env.BASE_URL ?? "https://doughmination.uk").replace(/\/+$/, "");
}
-/** CORS allow-list: built-in defaults plus anything in CORS_ORIGINS. */
+/** Any localhost origin, on any port and either scheme — local dev servers
+ * (Vite :5173, Next :3000, wrangler :8787, …) are always allowed. */
+export function isLocalhostOrigin(origin: string): boolean {
+ return /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/.test(origin);
+}
+
+/** CORS allow-list: built-in defaults plus anything in CORS_ORIGINS.
+ * Localhost origins are additionally allowed via isLocalhostOrigin(). */
export function corsOrigins(): string[] {
const defaults = [
- "http://localhost:8080",
- "http://127.0.0.1:8080",
"http://doughmination.uk",
"https://doughmination.uk",
"http://doughmination.co.uk",