mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 12:35:38 +01:00
fix(middleware): bring back middleware for TRACKER_SCRIPT_NAME functionality
This commit is contained in:
parent
3eabe9b958
commit
c0a9ceae2f
1 changed files with 21 additions and 0 deletions
21
middleware.ts
Normal file
21
middleware.ts
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue