@@ -19,6 +19,7 @@ import {
1919} from '@graphprotocol/indexer-common'
2020import { createCostServer } from './cost'
2121import { createOperatorServer } from './operator'
22+ import rateLimit from 'express-rate-limit'
2223
2324export interface ServerOptions {
2425 logger : Logger
@@ -139,6 +140,18 @@ export const createApp = async ({
139140
140141 const app = express ( )
141142
143+ // Limit status requests to 9000/30min (5/s)
144+ const slowLimiter = rateLimit ( {
145+ windowMs : 30 * 60 * 1000 , // 1 minutes
146+ max : 9000 ,
147+ } )
148+
149+ // Limit network requests to 90000/30min (50/s)
150+ const networkLimiter = rateLimit ( {
151+ windowMs : 30 * 60 * 1000 , // 1 minutes
152+ max : 90000 ,
153+ } )
154+
142155 // Log requests to the logger stream
143156 // eslint-disable-next-line @typescript-eslint/no-explicit-any
144157 app . use ( morgan ( 'tiny' , { stream : loggerStream } ) as any )
@@ -160,20 +173,23 @@ export const createApp = async ({
160173 // Endpoint for the public status API
161174 app . use (
162175 '/status' ,
176+ networkLimiter ,
163177 bodyParser . json ( ) ,
164178 await createStatusServer ( { graphNodeStatusEndpoint } ) ,
165179 )
166180
167181 // Endpoint for the public cost API
168182 app . use (
169183 '/cost' ,
184+ slowLimiter ,
170185 bodyParser . json ( ) ,
171186 await createCostServer ( { indexerManagementClient, metrics } ) ,
172187 )
173188
174189 // Endpoint for operator information
175190 app . use (
176191 '/operator' ,
192+ slowLimiter ,
177193 bodyParser . json ( ) ,
178194 await createOperatorServer ( { operatorPublicKey } ) ,
179195 )
@@ -187,6 +203,7 @@ export const createApp = async ({
187203 // Endpoint for network subgraph queries
188204 app . post (
189205 `/network` ,
206+ networkLimiter ,
190207 bodyParser . raw ( { type : 'application/json' } ) ,
191208 async ( req , res ) => {
192209 try {
0 commit comments