import dotenv from "dotenv"; import express, { type Request, type Response, type NextFunction, } from "express"; import cors from "cors"; import { WORDLIST } from "./wordlist"; import { getGroupName as getCategoryName } from "./ai"; import { rateLimit } from "express-rate-limit"; dotenv.config(); const PORT = 4000; const limiter = rateLimit({ windowMs: 1 * 60 * 1000, //5 minute limit: 20, // 20 requests per minute }); const app = express(); app.use(cors()); app.use(express.json()); app.use(limiter); app.set("trust proxy", "loopback"); // specify a single subnet app.get("/api/", (req, res) => { res.send("HEALTHY"); }); app.get("/api/random-words", (req, res) => { let words: string[] = []; while (words.length < 16) { const candidateWord = WORDLIST[Math.round(Math.random() * WORDLIST.length)]; if (candidateWord.length < 4) { continue; } words.push(candidateWord); } res.send(words); }); app.post("/api/group-words", async (req, res) => { res.send(await getCategoryName(req.body.words)); }); app.listen(PORT, () => { console.log("Initialized"); }); export default app;