Skip to content

Commit 36d3fc8

Browse files
committed
Added rate limiter
1 parent 9726be7 commit 36d3fc8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"lint": "eslint ."
2424
},
2525
"dependencies": {
26+
"@fastify/rate-limit": "^10.3.0",
2627
"@fastify/static": "^9.0.0",
2728
"@fastify/websocket": "^11.2.0",
2829
"@wdio/cli": "9.27.0",

packages/backend/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import url from 'node:url'
33

44
import Fastify, { type FastifyInstance, type FastifyRequest } from 'fastify'
55
import staticServer from '@fastify/static'
6+
import rateLimit from '@fastify/rate-limit'
67
import websocket from '@fastify/websocket'
78
import getPort from 'get-port'
89
import logger from '@wdio/logger'
@@ -54,6 +55,11 @@ export async function start(
5455
const appPath = await getDevtoolsApp()
5556

5657
server = Fastify({ logger: true })
58+
await server.register(rateLimit, {
59+
global: false,
60+
max: 100,
61+
timeWindow: '1 minute'
62+
})
5763
await server.register(websocket)
5864
await server.register(staticServer, {
5965
root: appPath
@@ -172,6 +178,14 @@ export async function start(
172178
// requests the file through this endpoint.
173179
server.get(
174180
'/api/video/:sessionId',
181+
{
182+
config: {
183+
rateLimit: {
184+
max: 30,
185+
timeWindow: '1 minute'
186+
}
187+
}
188+
},
175189
async (
176190
request: FastifyRequest<{ Params: { sessionId: string } }>,
177191
reply

0 commit comments

Comments
 (0)