feat: enable rate limit on API server (#15)

This commit is contained in:
Takeshi Kimata
2024-07-20 08:40:45 +09:00
committed by GitHub
parent a1ad775a7a
commit e0fa63db0f
3 changed files with 31 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
const express = require('express');
const RateLimit = require('express-rate-limit');
const path = require('path');
const { Sequelize } = require('sequelize');
const app = express();
@@ -15,6 +16,14 @@ app.use(cors(corsOptions));
// enable json middleware
app.use(express.json());
// enable rate limiter
const limiter = RateLimit({
windowMs: 60 * 60 * 1000, // 1h
max: 1000, // 1000 requests per hour
message: 'Too many requests from this IP, please try again after an hour',
});
app.use(limiter);
// Specify the directory to serve static files
app.use(express.static(path.join(__dirname, 'public')));