umami/pages/api/share/[id].js

23 lines
552 B
JavaScript
Raw Normal View History

2020-08-15 10:17:15 +02:00
import { getWebsiteByShareId } from 'lib/queries';
import { ok, notFound, methodNotAllowed } from 'lib/response';
import { createToken } from 'lib/crypto';
2020-08-15 10:17:15 +02:00
export default async (req, res) => {
const { id } = req.query;
if (req.method === 'GET') {
const website = await getWebsiteByShareId(id);
if (website) {
const websiteId = website.website_id;
const token = await createToken({ website_id: websiteId });
return ok(res, { websiteId, token });
2020-08-15 10:17:15 +02:00
}
return notFound(res);
}
return methodNotAllowed(res);
};