update middleware to allow static images. created prod env file

This commit is contained in:
2025-12-12 11:26:39 -05:00
parent 1757aba3e7
commit e2d0fb8003
5 changed files with 35 additions and 13 deletions
+4
View File
@@ -1,5 +1,9 @@
NEXT_PUBLIC_API_BASE_URL=http://localhost:8080 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_API_KEY=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
BREVO_LIST_ID=9 BREVO_LIST_ID=9
+9
View File
@@ -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
+1 -1
View File
@@ -28,7 +28,7 @@ const navItems = [
icon: <Layers className="h-4 w-4" />, icon: <Layers className="h-4 w-4" />,
}, },
{ {
label: "Products (TO DO)", label: "Products",
href: "/admin/products", href: "/admin/products",
icon: <Boxes className="h-4 w-4" />, icon: <Boxes className="h-4 w-4" />,
}, },
+2 -2
View File
@@ -24,12 +24,12 @@ export default function NotFound() {
Go Home Go Home
</Link> </Link>
<a {/* <a
href="https://battl.builders" href="https://battl.builders"
className="rounded-md border border-zinc-700 px-4 py-2 text-sm font-medium text-zinc-300 hover:bg-zinc-900 hover:border-zinc-600 transition-colors" className="rounded-md border border-zinc-700 px-4 py-2 text-sm font-medium text-zinc-300 hover:bg-zinc-900 hover:border-zinc-600 transition-colors"
> >
Learn More Learn More
</a> </a> */}
</div> </div>
<p className="mt-6 text-[11px] text-zinc-600"> <p className="mt-6 text-[11px] text-zinc-600">
+19 -10
View File
@@ -4,35 +4,44 @@ import type { NextRequest } from "next/server";
const LAUNCH_ONLY_ROOT = process.env.NEXT_PUBLIC_LAUNCH_ONLY_ROOT === "true"; const LAUNCH_ONLY_ROOT = process.env.NEXT_PUBLIC_LAUNCH_ONLY_ROOT === "true";
// Allow only root + essential static files // ✅ Forever allow list (always reachable even during launch-only mode)
const ALLOW = new Set([ const ALWAYS_ALLOW = new Set<string>([
"/", "/",
"/favicon.ico", "/favicon.ico",
"/robots.txt", "/robots.txt",
"/sitemap.xml", "/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) { export function middleware(req: NextRequest) {
if (!LAUNCH_ONLY_ROOT) return NextResponse.next(); if (!LAUNCH_ONLY_ROOT) return NextResponse.next();
const { pathname } = req.nextUrl; const { pathname } = req.nextUrl;
// Always allow Next internals + static assets // Always allow Next internals + static assets (public/ and _next/)
if ( if (
pathname.startsWith("/_next") || pathname.startsWith("/_next") ||
pathname.startsWith("/assets") || pathname.startsWith("/favicon") ||
pathname.startsWith("/images") pathname === "/robots.txt" ||
pathname === "/sitemap.xml" ||
PUBLIC_FILE.test(pathname)
) { ) {
return NextResponse.next(); return NextResponse.next();
} }
// Allow the root + a few public files // Allow the root + a few public files
if (ALLOW.has(pathname)) return NextResponse.next(); if (ALWAYS_ALLOW.has(pathname)) return NextResponse.next();
// Everything else: hide it // 🚫 Everything else: hide it
return NextResponse.rewrite(new URL("/404", req.url)); // or redirect to "/" return NextResponse.rewrite(new URL("/404", req.url));
} }
export const config = { 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)).*)",
],
}; };