Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Added CORS to website API endpoints.
Mike Caobf5068d32a9c
diff --git a/pages/api/account/index.js b/pages/api/account/index.jsindex 101d3e7fa..5afd82123 100644--- a/pages/api/account/index.js+++ b/pages/api/account/index.js@@ -34,7 +34,7 @@ export default async (req, res) => {return badRequest(res, 'Account already exists');}}- console.log('------------------\n', data);+const updated = await updateAccount(user_id, data);return ok(res, updated);diff --git a/pages/api/website/[id]/active.js b/pages/api/website/[id]/active.jsindex 280bc06e0..ad7f8991c 100644--- a/pages/api/website/[id]/active.js+++ b/pages/api/website/[id]/active.js@@ -1,9 +1,12 @@import { getActiveVisitors } from 'lib/queries';import { methodNotAllowed, ok, unauthorized } from 'lib/response';import { allowQuery } from 'lib/auth';+import { useCors } from 'lib/middleware';export default async (req, res) => {if (req.method === 'GET') {+ await useCors(req, res);+if (!(await allowQuery(req))) {return unauthorized(res);}diff --git a/pages/api/website/[id]/events.js b/pages/api/website/[id]/events.jsindex 7f348ee1d..974e79f31 100644--- a/pages/api/website/[id]/events.js+++ b/pages/api/website/[id]/events.js@@ -2,11 +2,14 @@ import moment from 'moment-timezone';import { getEventMetrics } from 'lib/queries';import { ok, badRequest, methodNotAllowed, unauthorized } from 'lib/response';import { allowQuery } from 'lib/auth';+import { useCors } from 'lib/middleware';const unitTypes = ['year', 'month', 'hour', 'day'];export default async (req, res) => {if (req.method === 'GET') {+ await useCors(req, res);+if (!(await allowQuery(req))) {return unauthorized(res);}diff --git a/pages/api/website/[id]/index.js b/pages/api/website/[id]/index.jsindex 74ce0f339..7018a01d9 100644--- a/pages/api/website/[id]/index.js+++ b/pages/api/website/[id]/index.js@@ -1,6 +1,7 @@import { deleteWebsite, getWebsiteById } from 'lib/queries';import { methodNotAllowed, ok, unauthorized } from 'lib/response';import { allowQuery } from 'lib/auth';+import { useCors } from 'lib/middleware';export default async (req, res) => {const { id } = req.query;@@ -8,6 +9,8 @@ export default async (req, res) => {const websiteId = +id;if (req.method === 'GET') {+ await useCors(req, res);+if (!(await allowQuery(req))) {return unauthorized(res);}diff --git a/pages/api/website/[id]/metrics.js b/pages/api/website/[id]/metrics.jsindex 675427db2..7e74f0445 100644--- a/pages/api/website/[id]/metrics.js+++ b/pages/api/website/[id]/metrics.js@@ -1,6 +1,7 @@import { getPageviewMetrics, getSessionMetrics, getWebsiteById } from 'lib/queries';import { ok, methodNotAllowed, unauthorized, badRequest } from 'lib/response';import { allowQuery } from 'lib/auth';+import { useCors } from 'lib/middleware';const sessionColumns = ['browser', 'os', 'device', 'country', 'language'];const pageviewColumns = ['url', 'referrer'];@@ -26,6 +27,8 @@ function getColumn(type) {export default async (req, res) => {if (req.method === 'GET') {+ await useCors(req, res);+if (!(await allowQuery(req))) {return unauthorized(res);}diff --git a/pages/api/website/[id]/pageviews.js b/pages/api/website/[id]/pageviews.jsindex e2069f8ca..41ea06eb9 100644--- a/pages/api/website/[id]/pageviews.js+++ b/pages/api/website/[id]/pageviews.js@@ -2,11 +2,14 @@ import moment from 'moment-timezone';import { getPageviewStats } from 'lib/queries';import { ok, badRequest, methodNotAllowed, unauthorized } from 'lib/response';import { allowQuery } from 'lib/auth';+import { useCors } from 'lib/middleware';const unitTypes = ['year', 'month', 'hour', 'day'];export default async (req, res) => {if (req.method === 'GET') {+ await useCors(req, res);+if (!(await allowQuery(req))) {return unauthorized(res);}diff --git a/pages/api/website/[id]/stats.js b/pages/api/website/[id]/stats.jsindex cdb374e2f..7b1c5cf0b 100644--- a/pages/api/website/[id]/stats.js+++ b/pages/api/website/[id]/stats.js@@ -1,9 +1,12 @@import { getWebsiteStats } from 'lib/queries';import { methodNotAllowed, ok, unauthorized } from 'lib/response';import { allowQuery } from 'lib/auth';+import { useCors } from 'lib/middleware';export default async (req, res) => {if (req.method === 'GET') {+ await useCors(req, res);+if (!(await allowQuery(req))) {return unauthorized(res);}