From d2c9c4546117379d766e2d8c4b007c5fd78a27b3 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Thu, 20 Apr 2023 01:52:49 -0700 Subject: [PATCH] Allow slashes in tracker names. --- docker/middleware.js | 2 +- next.config.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docker/middleware.js b/docker/middleware.js index fa6cbd99..85fe96d2 100644 --- a/docker/middleware.js +++ b/docker/middleware.js @@ -24,7 +24,7 @@ function customScriptName(req) { if (scriptName) { const url = req.nextUrl.clone(); const { pathname } = url; - const names = scriptName.split(',').map(name => name.trim()); + const names = scriptName.split(',').map(name => name.trim().replace(/^\/+/, '')); if (names.find(name => pathname.endsWith(name))) { url.pathname = '/script.js'; diff --git a/next.config.js b/next.config.js index 303ff64f..7d5fd565 100644 --- a/next.config.js +++ b/next.config.js @@ -49,10 +49,8 @@ if (process.env.TRACKER_SCRIPT_NAME) { if (names) { names.forEach(name => { - const slash = name.substring(0, 1) === '/' ? '' : '/'; - rewrites.push({ - source: `${slash}${name}`, + source: `/${name.replace(/^\/+/, '')}`, destination: '/script.js', }); });