mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Added middleware for docker.
This commit is contained in:
parent
3eabe9b958
commit
ac8d8bbd1e
4 changed files with 59 additions and 1 deletions
46
docker/middleware.js
Normal file
46
docker/middleware.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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;
|
||||
|
||||
if (pathname.endsWith(scriptName)) {
|
||||
url.pathname = '/script.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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue