-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
47 lines (41 loc) · 1.3 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
46
47
import fs from "fs";
import express from "express";
import path from "path";
import myData from "./data.js";
import clientRouter from "./routes/clientRoute.js";
import adminRouter from "./routes/adminRoute.js";
import authRouter from "./routes/authRoute.js";
import rateLimit from "express-rate-limit";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const limiter = rateLimit({
windowMs: 10 * 60 * 1000,
max: 400,
message: { status: 429, message: "Too many requests" },
});
const app = express();
var port = process.env.PORT || 3000;
var words = Object.keys(myData);
app.use(express.json());
//app.use(express.static(path.join(__dirname, 'public')))
app.use(limiter);
app.use("/admin/api", adminRouter);
app.use("/api", clientRouter);
app.use("/", authRouter);
app.get("/download/all/words", (req, res) => {
res.send(words.join(","));
});
app.get("/", (req, res) => {
res.sendFile("public/index.html", { root: __dirname });
});
app.get("/script.js", (req, res) => {
res.sendFile("public/script.js", { root: __dirname });
});
app.get("/image.png", (req, res) => {
res.sendFile("public/image.png", { root: __dirname });
});
app.listen(port, () => {
console.log("api started on port " + port);
});