From bbdb67206364b5c1d9bd5bf9cefd29a42fa35f62 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 2 Apr 2023 16:51:00 -0700 Subject: [PATCH] Removed middleware. --- middleware.js | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 middleware.js diff --git a/middleware.js b/middleware.js deleted file mode 100644 index 5afc4f90..00000000 --- a/middleware.js +++ /dev/null @@ -1,47 +0,0 @@ -import { NextResponse } from 'next/server'; - -export const config = { - matcher: '/:path*', -}; - -function customCollectEndpoint(req) { - const collectEndpoint = process.env.COLLECT_API_ENDPOINT; - - if (collectEndpoint) { - const url = req.nextUrl.clone(); - const { pathname } = url; - - if (pathname.endsWith(collectEndpoint)) { - url.pathname = '/api/send'; - return NextResponse.rewrite(url); - } - } -} - -function customScriptName(req) { - 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 = '/umami.js'; - return NextResponse.rewrite(url); - } - } -} - -export default function middleware(req) { - const fns = [customCollectEndpoint, customScriptName]; - - for (const fn of fns) { - const res = fn(req); - if (res) { - return res; - } - } - - return NextResponse.next(); -}