-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (27 loc) · 844 Bytes
/
index.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
// import Express from "express";
import express from "express";
import cors from 'cors';
import connection from "./config/db.js";
import route from './routes/route.js'
import "dotenv/config.js"
import {rateLimit} from 'express-rate-limit'
const app = express();
try{
await connection()
}catch(error){
console.log({error})
}
app.use(cors({credentials:true,origin:'*'}));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // Periode waktu dalam milidetik (di sini 15 menit)
max: 200, // Jumlah maksimal permintaan dalam periode waktu yang sama
message: 'Terlalu banyak permintaan dari IP Anda. Coba lagi nanti.',
});
app.use(limiter);
app.use(route);
const port = 5000;
app.listen(port, () => {
console.log(`server jalan di port ${port}`);
});