Domain validation. Filter domain from referrers.

This commit is contained in:
Mike Cao 2020-08-28 21:34:20 -07:00
parent a9765c7ea7
commit 5a4cde854a
13 changed files with 51 additions and 23 deletions

View file

@ -1,5 +1,6 @@
import { getRankings } from 'lib/queries';
import { ok, badRequest } from 'lib/response';
import { DOMAIN_REGEX } from '../../../../lib/constants';
const sessionColumns = ['browser', 'os', 'device', 'country'];
const pageviewColumns = ['url', 'referrer'];
@ -24,12 +25,18 @@ function getColumn(type) {
}
export default async (req, res) => {
const { id, type, start_at, end_at } = req.query;
const { id, type, start_at, end_at, domain } = req.query;
const websiteId = +id;
const startDate = new Date(+start_at);
const endDate = new Date(+end_at);
if (type !== 'event' && !sessionColumns.includes(type) && !pageviewColumns.includes(type)) {
if (
type !== 'event' &&
!sessionColumns.includes(type) &&
!pageviewColumns.includes(type) &&
domain &&
DOMAIN_REGEX.test(domain)
) {
return badRequest(res);
}
@ -39,6 +46,7 @@ export default async (req, res) => {
endDate,
getColumn(type),
getTable(type),
domain,
);
return ok(res, rankings);