Added option to remove trailing slash from urls.

This commit is contained in:
Mike Cao 2022-01-25 21:23:40 -08:00
parent 291db2b107
commit 6a8de2aeec
2 changed files with 10 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import { useCors, useSession } from 'lib/middleware';
import { getIpAddress } from 'lib/request';
import { ok, badRequest } from 'lib/response';
import { createToken } from 'lib/crypto';
import { removeTrailingSlash } from 'lib/url';
export default async (req, res) => {
await useCors(req, res);
@ -37,18 +38,20 @@ export default async (req, res) => {
await useSession(req, res);
const { type, payload } = req.body;
const {
body: { type, payload },
session: { website_id, session_id },
} = req;
if (type === 'pageview') {
const { url, referrer } = payload;
let { url, referrer, event_type, event_value } = payload;
if (process.env.REMOVE_TRAILING_SLASH) {
url = removeTrailingSlash(url);
}
if (type === 'pageview') {
await savePageView(website_id, session_id, url, referrer);
} else if (type === 'event') {
const { url, event_type, event_value } = payload;
await saveEvent(website_id, session_id, url, event_type, event_value);
} else {
return badRequest(res);

View File

@ -1,5 +1,5 @@
import { doNotTrack, hook } from '../lib/web';
import { removeTrailingSlash } from '../lib/url';
import { doNotTrack, hook } from 'lib/web';
import { removeTrailingSlash } from 'lib/url';
(window => {
const {