-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (35 loc) · 1.07 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import express from "express";
import cors from "cors";
import rateLimit from "express-rate-limit";
import { fetchUserProfile, fetchMultipleUserProfiles } from "./fetchUserProfile.js";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.use(
cors({
origin: "*",
})
);
app.set("trust proxy", 1);
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
limit: 10,
standardHeaders: "draft-7",
legacyHeaders: false,
});
app.use(limiter);
app.use(express.json());
app.use(express.static("public"));
app.get("/", (req, res) => {
res.set("Cache-Control", "no-store, no-cache, must-revalidate, private");
res.sendFile(path.join(__dirname, "public", "index.html"));
res.sendFile(path.join(__dirname, "public", "styles.css"));
});
app.get("/:username", fetchUserProfile);
app.post("/multi", fetchMultipleUserProfiles);
const PORT = 8000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});