From fa7cd1b9a2c52136edcf5af0205381d6adac3ebb Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Sun, 21 Dec 2025 01:25:00 -0500 Subject: [PATCH] feat: add middleware for zine.mycofi.earth subdomain routing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Routes zine.mycofi.earth root to /zine content so it works like zine.jeffemmett.com - showing the zine generator directly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- middleware.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 middleware.ts diff --git a/middleware.ts b/middleware.ts new file mode 100644 index 0000000..b8fcac5 --- /dev/null +++ b/middleware.ts @@ -0,0 +1,51 @@ +import { NextResponse } from 'next/server' +import type { NextRequest } from 'next/server' + +export function middleware(request: NextRequest) { + const host = request.headers.get('host') || '' + const pathname = request.nextUrl.pathname + + // Handle zine.mycofi.earth subdomain + if (host.startsWith('zine.')) { + // Don't rewrite if already accessing /zine paths or API/static files + if ( + pathname.startsWith('/zine') || + pathname.startsWith('/api/zine') || + pathname.startsWith('/_next') || + pathname.startsWith('/favicon') || + pathname.includes('.') + ) { + return NextResponse.next() + } + + // Rewrite root and other paths to /zine + const url = request.nextUrl.clone() + + if (pathname === '/') { + url.pathname = '/zine' + } else if (pathname.startsWith('/create')) { + url.pathname = `/zine${pathname}` + } else if (pathname.startsWith('/z/')) { + url.pathname = `/zine${pathname}` + } else { + // For any other path, try prepending /zine + url.pathname = `/zine${pathname}` + } + + return NextResponse.rewrite(url) + } + + return NextResponse.next() +} + +export const config = { + matcher: [ + /* + * Match all request paths except: + * - _next/static (static files) + * - _next/image (image optimization files) + * - favicon.ico (favicon file) + */ + '/((?!_next/static|_next/image|favicon.ico).*)', + ], +}