1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ratelimit } from "https://esm.town/v/rlimit/ratelimit?v=39";
import { twitterJSON } from "https://esm.town/v/stevekrouse/twitterJSON";
export default async function(req: Request): Promise<Response> {
if (req.headers.get("authorization") !== "Bearer " + Deno.env.get("boozedog"))
return Response.json("Unauthorized", { status: 401 });
const limit = await ratelimit("5/1h", "twitter-rl");
console.log(limit);
if (!limit.ok) {
return Response.json("Rate limit reached", { status: 429 });
}
let url = new URL(req.url);
console.log("https://api.twitter.com" + url.pathname + url.search);
return Response.json(
await twitterJSON({
url: "https://api.twitter.com/" + url.pathname + url.search,
bearerToken: Deno.env.get("twitter"),
}),
);
}