-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (30 loc) · 903 Bytes
/
index.js
File metadata and controls
37 lines (30 loc) · 903 Bytes
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
const express = require("express");
const cors = require("cors");
const rateLimit = require("express-rate-limit");
require("dotenv").config();
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || "localhost";
// Create a new express application
const app = express();
// Rate limiter
const limiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
max: 100, // Limit each IP to 100 requests per windowMs
});
app.use(limiter);
app.set("trust proxy", 1);
// Enable CORS
app.use(
cors({
origin: `http://${HOST}:8080`,
})
);
// Set static folder
// app.use("/home", express.static("public")); // http://localhost:3000/home/index.html can be given different path
app.use(express.static("public"));
// Routes
app.use("/", require("./routes"));
// Start the Express server
app.listen(PORT, HOST, () => {
console.log(`Server is running on http://${HOST}:${PORT}`);
});