Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { rateLimit } from "https://esm.town/v/stevekrouse/rateLimit?v=17";
export const auth = (req, res) => {
// check if we've exceed the ratelimiting for the current IP
if (!rateLimit(req.ip, 50)) {
return res.status(429).send("Rate limiting exceeded");
}
const domainAllowList = [
"http://localhost:3000",
"https://www.merlinmason.co.uk",
];
const deviceId: string = req.get("Authorization").replace("Bearer ", "") ??
"";
const validOrigin = domainAllowList.includes(req.get("origin"));
if (deviceId.length !== 32 || !validOrigin) {
return res.status(401).send("You must make an authenticated request");
}
return true;
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023