mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Merge pull request #1257 from rohandebsarkar/custom-endpoint
Adds suport custom collect API endpoint
This commit is contained in:
commit
eb538259fa
@ -101,6 +101,7 @@
|
||||
"devDependencies": {
|
||||
"@formatjs/cli": "^4.2.29",
|
||||
"@rollup/plugin-buble": "^0.21.3",
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"@svgr/webpack": "^6.2.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^7.32.0",
|
||||
|
@ -1,5 +1,19 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
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/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);
|
||||
|
@ -1,4 +1,5 @@
|
||||
import buble from '@rollup/plugin-buble';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
|
||||
export default {
|
||||
@ -7,5 +8,12 @@ export default {
|
||||
file: 'public/umami.js',
|
||||
format: 'iife',
|
||||
},
|
||||
plugins: [buble({ objectAssign: true }), terser({ compress: { evaluate: false } })],
|
||||
plugins: [
|
||||
replace({
|
||||
'/api/collect': process.env.COLLECT_API_ENDPOINT || '/api/collect',
|
||||
delimiters: ['', ''],
|
||||
}),
|
||||
buble({ objectAssign: true }),
|
||||
terser({ compress: { evaluate: false } }),
|
||||
],
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user