@@ -10,26 +10,14 @@ import article from '@/article-api/middleware/article'
1010import webhooks from '@/webhooks/middleware/webhooks.js'
1111import { ExtendedRequest } from '@/types'
1212import { noCacheControl } from './cache-control'
13- import { createRateLimiter } from '@/shielding/middleware/rate-limit'
1413
1514const router = express . Router ( )
1615
17- // Please make sure to rate limit all routes in this file.
18- const createAPIRateLimiter = ( hitsPerMin : number ) => createRateLimiter ( hitsPerMin , true )
19-
20- let eventsRouteRateLimit = 100
21- let internalRoutesRateLimit = 25 // Used internally, higher rate limits
22- let searchRoutesRateLimit = 15
23- let publicRoutesRateLimit = 10 // Used publicly, lower rate limits
24- if ( process . env . NODE_ENV === 'test' ) {
25- searchRoutesRateLimit = 2 // set to 2 so that api-ai-search.ts test will exceed rate limit after 3 requests
26- }
27-
28- router . use ( '/events' , createAPIRateLimiter ( eventsRouteRateLimit ) , events )
29- router . use ( '/webhooks' , createAPIRateLimiter ( internalRoutesRateLimit ) , webhooks )
30- router . use ( '/anchor-redirect' , createAPIRateLimiter ( internalRoutesRateLimit ) , anchorRedirect )
31- router . use ( '/pagelist' , createAPIRateLimiter ( publicRoutesRateLimit ) , pageList )
32- router . use ( '/article' , createAPIRateLimiter ( publicRoutesRateLimit ) , article )
16+ router . use ( '/events' , events )
17+ router . use ( '/webhooks' , webhooks )
18+ router . use ( '/anchor-redirect' , anchorRedirect )
19+ router . use ( '/pagelist' , pageList )
20+ router . use ( '/article' , article )
3321
3422// The purpose of this is for convenience to everyone who runs this code
3523// base locally but don't have an Elasticsearch server locally.
@@ -38,14 +26,13 @@ router.use('/article', createAPIRateLimiter(publicRoutesRateLimit), article)
3826// server or the known credentials to a remote Elasticsearch. Whenever
3927// that's the case, they can just HTTP proxy to the production server.
4028if ( process . env . CSE_COPILOT_ENDPOINT || process . env . NODE_ENV === 'test' ) {
41- router . use ( '/ai-search' , createAPIRateLimiter ( searchRoutesRateLimit ) , aiSearch )
29+ router . use ( '/ai-search' , aiSearch )
4230} else {
4331 console . log (
4432 'Proxying AI Search requests to docs.github.com. To use the cse-copilot endpoint, set the CSE_COPILOT_ENDPOINT environment variable.' ,
4533 )
4634 router . use (
4735 '/ai-search' ,
48- createAPIRateLimiter ( searchRoutesRateLimit ) ,
4936 createProxyMiddleware ( {
5037 target : 'https://docs.github.com' ,
5138 changeOrigin : true ,
@@ -56,11 +43,10 @@ if (process.env.CSE_COPILOT_ENDPOINT || process.env.NODE_ENV === 'test') {
5643 )
5744}
5845if ( process . env . ELASTICSEARCH_URL ) {
59- router . use ( '/search' , createAPIRateLimiter ( searchRoutesRateLimit ) , search )
46+ router . use ( '/search' , search )
6047} else {
6148 router . use (
6249 '/search' ,
63- createAPIRateLimiter ( searchRoutesRateLimit ) ,
6450 createProxyMiddleware ( {
6551 target : 'https://docs.github.com' ,
6652 changeOrigin : true ,
@@ -74,7 +60,7 @@ if (process.env.ELASTICSEARCH_URL) {
7460// We need access to specific httpOnly cookies set on github.com from the client
7561// The only way to access these on the client is to fetch them from the server
7662// Limit this endpoint to 1req/min because a client should only call this route once
77- router . get ( '/cookies' , createAPIRateLimiter ( 1 ) , ( req , res ) => {
63+ router . get ( '/cookies' , ( req , res ) => {
7864 noCacheControl ( res )
7965 const cookies = {
8066 isStaff : Boolean ( req . cookies ?. staffonly ?. startsWith ( 'yes' ) ) || false ,
0 commit comments