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

25 lines
553 B
JavaScript
Raw Normal View History

2020-08-18 09:51:32 +02:00
import { getActiveVisitors } from 'lib/queries';
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
import { allowQuery } from 'lib/auth';
2022-04-04 09:33:20 +02:00
import { useCors } from 'lib/middleware';
2020-08-18 09:51:32 +02:00
export default async (req, res) => {
2020-09-11 22:49:43 +02:00
if (req.method === 'GET') {
2022-04-04 09:33:20 +02:00
await useCors(req, res);
if (!(await allowQuery(req))) {
return unauthorized(res);
}
2020-09-11 22:49:43 +02:00
const { id } = req.query;
2020-08-18 09:51:32 +02:00
const websiteId = +id;
const result = await getActiveVisitors(websiteId);
2020-09-11 22:49:43 +02:00
return ok(res, result);
}
return methodNotAllowed(res);
2020-08-18 09:51:32 +02:00
};