-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (25 loc) · 744 Bytes
/
server.js
File metadata and controls
32 lines (25 loc) · 744 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
import dotenv from "dotenv";
dotenv.config();
import app from "./app.js";
import { connectDB } from "./db/db.js";
import { connectRedis } from "./config/redis.js";
import { CreateRateLimiter } from "./middlewares/ratelimiting.js";
const PORT = process.env.PORT || 3000;
const startServer = async () => {
try {
// connect infra
await connectRedis();
await connectDB();
// create rate limiter AFTER redis is ready
const rateLimiter = CreateRateLimiter();
// apply rate limiting
app.use("/url", rateLimiter);
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
} catch (err) {
console.error("Failed to start server", err);
process.exit(1);
}
};
startServer();