Skip to content

Instantly share code, notes, and snippets.

@popeating
Created September 5, 2022 20:30
Show Gist options
  • Save popeating/e867cdc19bd34a31d490db91c1dfb58e to your computer and use it in GitHub Desktop.
Save popeating/e867cdc19bd34a31d490db91c1dfb58e to your computer and use it in GitHub Desktop.
import { NextRequest, NextResponse } from 'next/server'
export default async function middleware(req: NextRequest) {
const bot=checkBot(req.headers.user-agent);
if (bot=== true) {
const url = req.nextUrl;
url.pathname = `/404`;
return NextResponse.rewrite(url);
}
return NextResponse.next();
}
function checkBot(useragent) {
//logic to check for a bot user agent
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment