-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
23 lines (20 loc) · 767 Bytes
/
middleware.ts
File metadata and controls
23 lines (20 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { chain } from "@/middlewares/chain";
import { withAuthMiddleware } from "@/middlewares/withAuthMiddleware";
import { withI18nMiddleware } from "@/middlewares/withI18nMiddleware";
import { withRateLimitMiddleware } from "@/middlewares/withRateLimitMiddleware";
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.cachedFixedWindow(10, "10 s"),
ephemeralCache: new Map(),
prefix: "ratelimit",
});
export default chain([
withRateLimitMiddleware(ratelimit),
withAuthMiddleware,
withI18nMiddleware, // maybe this should be before auth
]);
export const config = {
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};