Merge pull request #1257 from rohandebsarkar/custom-endpoint

Adds suport custom collect API endpoint
This commit is contained in:
Mike Cao 2022-07-04 23:56:39 -07:00 committed by GitHub
commit eb538259fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 942 additions and 932 deletions

View File

@ -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",

View File

@ -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);

View File

@ -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 } }),
],
};

1847
yarn.lock

File diff suppressed because it is too large Load Diff