Skip to content

Commit

Permalink
Configure rate limits for api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
petterhj committed Oct 27, 2023
1 parent fc5b0af commit f8a4999
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions functions/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functions from 'firebase-functions';

import express from 'express';
import rateLimit from 'express-rate-limit';
import cors from 'cors';
import morgan from 'morgan';

Expand All @@ -12,9 +13,16 @@ import kpiRoutes from './routes/kpi.js';
import statusRoutes from './routes/status.js';
import userRoutes from './routes/user.js';

const apiLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // max 100 requests per window
message: 'Too many requests, please try again later.',
});

const app = express();

app.use(cors());
app.use(apiLimiter);
app.use(express.json());
app.use(morgan('combined'));

Expand Down

0 comments on commit f8a4999

Please sign in to comment.