update middleware to allow static images. created prod env file
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -28,7 +28,7 @@ const navItems = [
|
||||
icon: <Layers className="h-4 w-4" />,
|
||||
},
|
||||
{
|
||||
label: "Products (TO DO)",
|
||||
label: "Products",
|
||||
href: "/admin/products",
|
||||
icon: <Boxes className="h-4 w-4" />,
|
||||
},
|
||||
|
||||
+2
-2
@@ -24,12 +24,12 @@ export default function NotFound() {
|
||||
Go Home
|
||||
</Link>
|
||||
|
||||
<a
|
||||
{/* <a
|
||||
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"
|
||||
>
|
||||
Learn More
|
||||
</a>
|
||||
</a> */}
|
||||
</div>
|
||||
|
||||
<p className="mt-6 text-[11px] text-zinc-600">
|
||||
|
||||
+19
-10
@@ -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<string>([
|
||||
"/",
|
||||
"/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)).*)",
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user