@@ -12,7 +12,7 @@ import {createWriteStream, existsSync, mkdirSync} from "fs";
12
12
import { SocketManager } from "./socketManager" ;
13
13
import { HyperionModuleLoader } from "../modules/loader" ;
14
14
import { extendedActions } from "./routes/v2-history/get_actions/definitions" ;
15
- import { Socket , io } from "socket.io-client" ;
15
+ import { io , Socket } from "socket.io-client" ;
16
16
17
17
class HyperionApiServer {
18
18
@@ -93,38 +93,42 @@ class HyperionApiServer {
93
93
94
94
const ioRedisClient = new IORedis ( this . manager . conn . redis ) ;
95
95
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 ;
102
103
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
+ }
106
120
}
107
121
108
- const api_rate_limit = {
109
- max : rateLimiterRPM ,
110
- allowList : rateLimiterWhitelist ,
111
- timeWindow : '1 minute' ,
112
- redis : ioRedisClient
113
- } ;
114
-
115
122
if ( this . conf . features . streaming . enable ) {
116
123
this . activateStreaming ( ) ;
117
124
}
118
125
119
126
const docsConfig = generateOpenApiConfig ( this . manager . config ) ;
127
+ if ( docsConfig ) {
128
+ pluginParams . fastify_swagger = docsConfig ;
129
+ }
120
130
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 ) ;
128
132
129
133
this . addGenericTypeParsing ( ) ;
130
134
}
0 commit comments