umami/pages/api/websites/[id]/active.js

24 lines
565 B
JavaScript
Raw Normal View History

2022-08-29 03:20:54 +00:00
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { allowQuery } from 'lib/auth';
2022-10-12 20:11:44 +00:00
import { useAuth, useCors } from 'lib/middleware';
2022-07-12 21:14:36 +00:00
import { getActiveVisitors } from 'queries';
2020-08-18 07:51:32 +00:00
export default async (req, res) => {
2022-10-12 20:11:44 +00:00
await useCors(req, res);
await useAuth(req, res);
2022-04-04 07:33:20 +00:00
2022-10-12 20:11:44 +00:00
if (req.method === 'GET') {
if (!(await allowQuery(req))) {
return unauthorized(res);
}
2022-10-12 02:37:38 +00:00
const { id: websiteId } = req.query;
2022-10-11 00:01:48 +00:00
const result = await getActiveVisitors(websiteId);
2020-09-11 20:49:43 +00:00
return ok(res, result);
}
return methodNotAllowed(res);
2020-08-18 07:51:32 +00:00
};