nhfs
Version:
NHFS — A sleek HTTP file server for the web built with Next.js and HeroUI. (Alpha)
20 lines (14 loc) • 445 B
text/typescript
import { NextRequest, NextResponse } from 'next/server';
export function middleware(req: NextRequest) {
// Check if the request is to download the file
const url = req.nextUrl.clone();
const isDownload = url.searchParams.get('dl') === 'true';
if (isDownload) {
url.pathname = `/nhfs_dl${url.pathname}`;
return NextResponse.rewrite(url);
}
return NextResponse.next();
}
export const config = {
matcher: ['/:path*'],
};