Skip to content

Commit 4bb2d72

Browse files
committed
refactor: Dynamically load global-agent using createRequire and ignore generated agent files.
1 parent c1ab149 commit 4bb2d72

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ explorer
5252
.cli
5353
*.deb
5454

55+
.agents
56+
5557
# Snapshots
5658
snapshots
57-
5859
plugins

src/api/server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { HyperionModuleLoader } from '../indexer/modules/loader.js';
1919
import { extendedActions } from './routes/v2-history/get_actions/definitions.js';
2020
import { CacheManager } from './helpers/cacheManager.js';
2121

22-
import { bootstrap } from 'global-agent';
22+
import { createRequire } from 'node:module';
2323
import { FastifySwaggerUiOptions } from '@fastify/swagger-ui';
2424
import { QRYBasePublisher } from './qry-hub/base-publisher.js';
2525
import { getApiUsageHistory } from './helpers/functions.js';
@@ -60,6 +60,8 @@ class HyperionApiServer {
6060
this.conf = cm.config;
6161

6262
if (this.conf.settings.use_global_agent) {
63+
const require = createRequire(import.meta.url);
64+
const { bootstrap } = require('global-agent');
6365
bootstrap();
6466
}
6567

src/indexer/modules/master.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import cluster, { Worker } from 'cluster';
77

88
import { createWriteStream, existsSync, mkdirSync, readFileSync, symlinkSync, unlinkSync, writeFileSync, WriteStream } from 'fs';
99

10-
import { bootstrap } from 'global-agent';
10+
import { createRequire } from 'node:module';
1111
import { Redis } from 'ioredis';
1212
import { Db, IndexDescription } from 'mongodb';
1313
import path from 'path';
@@ -185,6 +185,8 @@ export class HyperionMaster {
185185
this.conf = this.cm.config;
186186

187187
if (this.conf.settings.use_global_agent) {
188+
const require = createRequire(import.meta.url);
189+
const { bootstrap } = require('global-agent');
188190
bootstrap();
189191
}
190192

0 commit comments

Comments
 (0)