mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
35 lines
731 B
JavaScript
35 lines
731 B
JavaScript
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|
import { deleteWebsite, getWebsiteById } from 'queries';
|
|
import { allowQuery } from 'lib/auth';
|
|
import { useCors } from 'lib/middleware';
|
|
|
|
export default async (req, res) => {
|
|
const { id } = req.query;
|
|
|
|
const websiteId = +id;
|
|
|
|
if (req.method === 'GET') {
|
|
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);
|
|
};
|