Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

express-rate-limitを設定 #64

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@types/multer": "^1.4.12",
"express": "^4.21.1",
"express-rate-limit": "^7.4.1",
"firebase-admin": "^12.7.0",
"firebase-functions": "^6.1.0",
"helmet": "^8.0.0",
Expand Down
17 changes: 16 additions & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import cors from "cors";
import express from "express";
import rateLimit from "express-rate-limit";

Check warning on line 12 in functions/src/index.ts

View workflow job for this annotation

GitHub Actions / lint-check-functions

Using exported name 'rateLimit' as identifier for default import
import admin from "firebase-admin";
import * as logger from "firebase-functions/logger";
import { onRequest } from "firebase-functions/v2/https";
Expand All @@ -29,6 +30,21 @@
app.use(cors());
app.use(express.json());

// 10分間で最大300回に制限
app.use(
rateLimit({
windowMs: 5 * 60 * 1000,
max: 1000,
})
);
// 1時間で最大1000回に制限
app.use(
rateLimit({
windowMs: 10 * 60 * 1000,
max: 20,
})
);

import goalRouter from "./routers/goalRouter";
import postRouter from "./routers/postRouter";
import userRouer from "./routers/userRouter";
Expand All @@ -44,7 +60,6 @@
res.send("Hello World!");
});

// /user/:userName
export const firestore = onRequest({ region: region }, async (req, res) => {
app(req, res);
});