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

35 lines
731 B
JavaScript
Raw Normal View History

2022-08-29 05:20:54 +02:00
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
2022-07-12 23:14:36 +02:00
import { deleteWebsite, getWebsiteById } from 'queries';
import { allowQuery } from 'lib/auth';
2022-04-04 09:33:20 +02:00
import { useCors } from 'lib/middleware';
export default async (req, res) => {
const { id } = req.query;
const websiteId = +id;
if (req.method === 'GET') {
2022-04-04 09:33:20 +02:00
await useCors(req, res);
if (!(await allowQuery(req))) {
return unauthorized(res);
}
const website = await getWebsiteById(websiteId);
return ok(res, website);
}
if (req.method === 'DELETE') {
if (!(await allowQuery(req, true))) {
return unauthorized(res);
}
await deleteWebsite(websiteId);
return ok(res);
}
return methodNotAllowed(res);
};