Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Adds support for `customCollectEndpoint`

rohandebsarkarae48ff0e68fc
diff --git a/pages/_middleware.js b/pages/_middleware.js
index b8c66e945..b30ff1d40 100644
--- a/pages/_middleware.js
+++ b/pages/_middleware.js
@@ -1,5 +1,19 @@
import { NextResponse } from 'next/server';
+function customCollectEndpoint(req) {
+ const collectEndpoint = process.env.API_COLLECT_ENDPOINT;
+
+ if (collectEndpoint) {
+ const url = req.nextUrl.clone();
+ const { pathname } = url;
+
+ if (pathname.endsWith(collectEndpoint)) {
+ url.pathname = '/api/collect';
+ return NextResponse.rewrite(url);
+ }
+ }
+}
+
function customScriptName(req) {
const scriptName = process.env.TRACKER_SCRIPT_NAME;
@@ -24,7 +38,7 @@ function forceSSL(req, res) {
}
export function middleware(req) {
- const fns = [customScriptName];
+ const fns = [customCollectEndpoint, customScriptName];
for (const fn of fns) {
const res = fn(req);