feat: Add user agent check

Add code to check if useragent is a browser
This commit is contained in:
Ayane Satomi 2023-10-23 13:32:04 +00:00
parent cdf547e4bd
commit 725c7a1d24

View file

@ -74,6 +74,17 @@ export const handler: Handlers = {
},
POST: async (req, ctx) => {
const body = await req.json();
const headers = req.headers;
// check if useragent is a browser
// we can use the Sec-Ch-Ua header but it's not supported by all browsers
if (!headers.get("sec-ch-ua")) {
return new Response("", {
status: 403,
statusText: "Forbidden",
});
}
await setGlobalStatistics(body.data);
const updatedCount = await getGlobalStatistics();