refactor: change tracker path

This commit is contained in:
moonrailgun 2023-10-29 01:26:02 +08:00
parent b9d9391342
commit e53de57720
2 changed files with 7 additions and 5 deletions

View File

@ -43,7 +43,7 @@ websiteRouter.post(
.matches(/event|identify/i) .matches(/event|identify/i)
), ),
async (req, res) => { async (req, res) => {
// https://github1s.com/umami-software/umami/blob/master/src/pages/api/send.ts // Reference: https://github1s.com/umami-software/umami/blob/master/src/pages/api/send.ts
const { type, payload } = req.body; const { type, payload } = req.body;
const { const {

View File

@ -47,10 +47,11 @@
}; };
const getPath = (url) => { const getPath = (url) => {
if (url.substring(0, 4) === 'http') { try {
return '/' + url.split('/').splice(3).join('/'); return new URL(url).pathname;
} catch (e) {
return url;
} }
return url;
}; };
const getPayload = () => ({ const getPayload = () => ({
@ -199,7 +200,8 @@
headers, headers,
}) })
.then((res) => res.text()) .then((res) => res.text())
.then((text) => (cache = text)); .then((text) => (cache = text))
.catch(() => {});
}; };
const track = (obj, data) => { const track = (obj, data) => {