@@ -12,7 +12,7 @@ import {createWriteStream, existsSync, mkdirSync} from "fs";
1212import { SocketManager } from "./socketManager" ;
1313import { HyperionModuleLoader } from "../modules/loader" ;
1414import { extendedActions } from "./routes/v2-history/get_actions/definitions" ;
15- import { Socket , io } from "socket.io-client" ;
15+ import { io , Socket } from "socket.io-client" ;
1616
1717class HyperionApiServer {
1818
@@ -93,38 +93,42 @@ class HyperionApiServer {
9393
9494 const ioRedisClient = new IORedis ( this . manager . conn . redis ) ;
9595
96- let rateLimiterWhitelist = [ '127.0.0.1' ] ;
97-
98- if ( this . conf . api . rate_limit_allow && this . conf . api . rate_limit_allow . length > 0 ) {
99- const tempSet = new Set < string > ( [ '127.0.0.1' , ...this . conf . api . rate_limit_allow ] ) ;
100- rateLimiterWhitelist = [ ...tempSet ] ;
101- }
96+ const pluginParams = {
97+ fastify_elasticsearch : {
98+ client : this . manager . elasticsearchClient
99+ } ,
100+ fastify_redis : this . manager . conn . redis ,
101+ fastify_eosjs : this . manager ,
102+ } as any ;
102103
103- let rateLimiterRPM = 1000 ;
104- if ( this . conf . api . rate_limit_rpm ) {
105- rateLimiterRPM = this . conf . api . rate_limit_rpm ;
104+ if ( ! this . conf . api . disable_rate_limit ) {
105+ let rateLimiterWhitelist = [ '127.0.0.1' ] ;
106+ if ( this . conf . api . rate_limit_allow && this . conf . api . rate_limit_allow . length > 0 ) {
107+ const tempSet = new Set < string > ( [ '127.0.0.1' , ...this . conf . api . rate_limit_allow ] ) ;
108+ rateLimiterWhitelist = [ ...tempSet ] ;
109+ }
110+ let rateLimiterRPM = 1000 ;
111+ if ( this . conf . api . rate_limit_rpm ) {
112+ rateLimiterRPM = this . conf . api . rate_limit_rpm ;
113+ }
114+ pluginParams . fastify_rate_limit = {
115+ max : rateLimiterRPM ,
116+ allowList : rateLimiterWhitelist ,
117+ timeWindow : '1 minute' ,
118+ redis : ioRedisClient
119+ }
106120 }
107121
108- const api_rate_limit = {
109- max : rateLimiterRPM ,
110- allowList : rateLimiterWhitelist ,
111- timeWindow : '1 minute' ,
112- redis : ioRedisClient
113- } ;
114-
115122 if ( this . conf . features . streaming . enable ) {
116123 this . activateStreaming ( ) ;
117124 }
118125
119126 const docsConfig = generateOpenApiConfig ( this . manager . config ) ;
127+ if ( docsConfig ) {
128+ pluginParams . fastify_swagger = docsConfig ;
129+ }
120130
121- registerPlugins ( this . fastify , {
122- fastify_elasticsearch : { client : this . manager . elasticsearchClient } ,
123- fastify_swagger : docsConfig ,
124- fastify_rate_limit : api_rate_limit ,
125- fastify_redis : this . manager . conn . redis ,
126- fastify_eosjs : this . manager ,
127- } ) ;
131+ registerPlugins ( this . fastify , pluginParams ) ;
128132
129133 this . addGenericTypeParsing ( ) ;
130134 }
0 commit comments