From e2d0fb800390d8228436faeeb7fbb75e717586f5 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 12 Dec 2025 11:26:39 -0500 Subject: [PATCH] update middleware to allow static images. created prod env file --- .env.local | 4 ++++ .env.production | 9 +++++++++ app/admin/layout.tsx | 2 +- app/not-found.tsx | 4 ++-- middleware.ts | 29 +++++++++++++++++++---------- 5 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 .env.production diff --git a/.env.local b/.env.local index 6425cca..5177f68 100644 --- a/.env.local +++ b/.env.local @@ -1,5 +1,9 @@ NEXT_PUBLIC_API_BASE_URL=http://localhost:8080 +# Middleware to limited site to only root page +NEXT_PUBLIC_LAUNCH_ONLY_ROOT=true + +# Brevo API key for beta sign up collection BREVO_API_KEY=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 BREVO_LIST_ID=9 diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..86ef4d5 --- /dev/null +++ b/.env.production @@ -0,0 +1,9 @@ + +NEXT_PUBLIC_API_BASE_URL=http://localhost:8080 + +# Middleware to limited site to only root page +NEXT_PUBLIC_LAUNCH_ONLY_ROOT=true + +# Brevo API key for beta sign up collection +BREVO_API_KEY=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 +BREVO_LIST_ID=9 diff --git a/app/admin/layout.tsx b/app/admin/layout.tsx index 910153e..b71f547 100644 --- a/app/admin/layout.tsx +++ b/app/admin/layout.tsx @@ -28,7 +28,7 @@ const navItems = [ icon: , }, { - label: "Products (TO DO)", + label: "Products", href: "/admin/products", icon: , }, diff --git a/app/not-found.tsx b/app/not-found.tsx index d89982d..12407f0 100644 --- a/app/not-found.tsx +++ b/app/not-found.tsx @@ -24,12 +24,12 @@ export default function NotFound() { Go Home - Learn More - + */}

diff --git a/middleware.ts b/middleware.ts index 1134aa2..c1032d0 100644 --- a/middleware.ts +++ b/middleware.ts @@ -4,35 +4,44 @@ import type { NextRequest } from "next/server"; const LAUNCH_ONLY_ROOT = process.env.NEXT_PUBLIC_LAUNCH_ONLY_ROOT === "true"; -// Allow only root + essential static files -const ALLOW = new Set([ +// ✅ Forever allow list (always reachable even during launch-only mode) +const ALWAYS_ALLOW = new Set([ "/", "/favicon.ico", "/robots.txt", "/sitemap.xml", ]); +// Match common public/static file extensions so middleware never blocks them +const PUBLIC_FILE = /\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|json|woff|woff2|ttf|eot)$/i; + export function middleware(req: NextRequest) { if (!LAUNCH_ONLY_ROOT) return NextResponse.next(); const { pathname } = req.nextUrl; - // Always allow Next internals + static assets + // ✅ Always allow Next internals + static assets (public/ and _next/) if ( pathname.startsWith("/_next") || - pathname.startsWith("/assets") || - pathname.startsWith("/images") + pathname.startsWith("/favicon") || + pathname === "/robots.txt" || + pathname === "/sitemap.xml" || + PUBLIC_FILE.test(pathname) ) { return NextResponse.next(); } - // Allow the root + a few public files - if (ALLOW.has(pathname)) return NextResponse.next(); + // ✅ Allow the root + a few public files + if (ALWAYS_ALLOW.has(pathname)) return NextResponse.next(); - // Everything else: hide it - return NextResponse.rewrite(new URL("/404", req.url)); // or redirect to "/" + // 🚫 Everything else: hide it + return NextResponse.rewrite(new URL("/404", req.url)); } export const config = { - matcher: ["/:path*"], + // Run middleware on everything *except* Next internals and obvious static files. + // This keeps launch gating from ever breaking your logo/images/fonts/etc. + matcher: [ + "/((?!_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map|txt|xml|json|woff|woff2|ttf|eot)).*)", + ], }; \ No newline at end of file