Skip to content

Commit

Permalink
conditionally import mongodb plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
igorls committed Nov 9, 2024
1 parent 9199353 commit e4d198a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/api/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import fastify_eosjs from "./plugins/fastify-eosjs.js";

export async function registerPlugins(server: Fastify.FastifyInstance<Server, IncomingMessage, ServerResponse>, params: any) {
server.register(fastifyElasticsearch, params.fastify_elasticsearch);
server.register(fastifyMongodb, params.fastify_mongo);

if (params.fastify_mongo) {
server.register(fastifyMongodb, params.fastify_mongo);
}

server.register(fastifyCors);
server.register(formBodyPlugin);
server.register(fastifyRedis, params.fastify_redis);
Expand Down
14 changes: 5 additions & 9 deletions src/api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class HyperionApiServer {

// hLog(`Static Assets Dir: ${staticAssetsDir}`);

const pluginParams = {
this.pluginParams = {
fastify_elasticsearch: {
client: this.manager.elasticsearchClient
},
Expand All @@ -163,9 +163,7 @@ class HyperionApiServer {
} as any;

if (this.conf.indexer.experimental_mongodb_state) {
pluginParams.fastify_mongo = {
client: this.manager.mongodbClient
} as FastifyMongodbOptions;
this.pluginParams.fastify_mongo = {client: this.manager.mongodbClient} as FastifyMongodbOptions;
}

if (!this.conf.api.disable_rate_limit) {
Expand All @@ -178,7 +176,7 @@ class HyperionApiServer {
if (this.conf.api.rate_limit_rpm) {
rateLimiterRPM = this.conf.api.rate_limit_rpm;
}
pluginParams.fastify_rate_limit = {
this.pluginParams.fastify_rate_limit = {
max: rateLimiterRPM,
allowList: rateLimiterWhitelist,
timeWindow: '1 minute',
Expand All @@ -196,8 +194,8 @@ class HyperionApiServer {

const docsConfig = generateOpenApiConfig(this.manager.config);
if (docsConfig) {
pluginParams.fastify_swagger = docsConfig;
pluginParams.fastify_swagger_ui = {
this.pluginParams.fastify_swagger = docsConfig;
this.pluginParams.fastify_swagger_ui = {
logo: {
type: 'image/svg+xml',
content: headerLogo,
Expand All @@ -220,8 +218,6 @@ class HyperionApiServer {
},
} as FastifySwaggerUiOptions;
}

this.pluginParams = pluginParams;
}

activateStreaming() {
Expand Down

0 comments on commit e4d198a

Please sign in to comment.