support multiple track script name

This commit is contained in:
Randy 2022-03-19 14:18:32 +08:00
parent 2b4ddb5388
commit 2bd3ddf6ec

View File

@ -15,10 +15,15 @@ function customScriptName(req) {
const scriptName = process.env.TRACKER_SCRIPT_NAME;
if (scriptName) {
const names = scriptName.split(',').map(name => name + '.js');
const url = req.nextUrl.clone();
const { pathname } = url;
if (pathname.endsWith(`/${scriptName}.js`)) {
const pathNameParts = pathname.split('/');
const lastPathName = pathNameParts[pathNameParts.length - 1];
if (names.indexOf(lastPathName) !== -1) {
url.pathname = '/umami.js';
return NextResponse.rewrite(url);
}