fix(middleware): bring back middleware for TRACKER_SCRIPT_NAME functionality
parent
3eabe9b958
commit
c0a9ceae2f
|
@ -0,0 +1,21 @@
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import type { NextRequest } from 'next/server';
|
||||||
|
|
||||||
|
export async function middleware(req: NextRequest) {
|
||||||
|
const scriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||||
|
|
||||||
|
if (scriptName) {
|
||||||
|
const url = req.nextUrl.clone();
|
||||||
|
const { pathname } = url;
|
||||||
|
const names = scriptName.split(',').map(name => name.trim() + '.js');
|
||||||
|
|
||||||
|
if (names.find(name => pathname.endsWith(name))) {
|
||||||
|
url.pathname = '/script.js';
|
||||||
|
return NextResponse.rewrite(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: '/:path*',
|
||||||
|
};
|
Loading…
Reference in New Issue