diff --git a/backend/src/federation/index.ts b/backend/src/federation/index.ts index d91e1f2ee..8974c4e45 100644 --- a/backend/src/federation/index.ts +++ b/backend/src/federation/index.ts @@ -21,7 +21,10 @@ const nodeAPI = { API_2_00: `${nodeURL}/graphql/2_00/`, } -export const startDHT = async (connection: Connection, topic: string): Promise => { +export const startDHT = async ( + connection: Connection, + topic: string, +): Promise => { try { const TOPIC = DHT.hash(Buffer.from(topic)) diff --git a/backend/src/index.ts b/backend/src/index.ts index 4c08b422d..5c0f0c293 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,12 +1,13 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import createServer from './server/createServer' +import { startDHT } from '@/federation/index' // config import CONFIG from './config' async function main() { - const { app } = await createServer() + const { app, con } = await createServer() app.listen(CONFIG.PORT, () => { // eslint-disable-next-line no-console @@ -16,6 +17,11 @@ async function main() { console.log(`GraphIQL available at http://localhost:${CONFIG.PORT}`) } }) + + // start DHT hyperswarm when DHT_TOPIC is set in .env + if (CONFIG.DHT_TOPIC) { + await startDHT(con, CONFIG.DHT_TOPIC) + } } main().catch((e) => { diff --git a/backend/src/server/createServer.ts b/backend/src/server/createServer.ts index 88a30c93d..8ae4675db 100644 --- a/backend/src/server/createServer.ts +++ b/backend/src/server/createServer.ts @@ -22,9 +22,6 @@ import schema from '@/graphql/schema' import { elopageWebhook } from '@/webhook/elopage' import { Connection } from '@dbTools/typeorm' -// DHT -import { startDHT } from '@/federation/index' - import { apolloLogger } from './logger' import { Logger } from 'log4js' @@ -55,11 +52,6 @@ const createServer = async ( throw new Error('Fatal: Database Version incorrect') } - // start DHT hyperswarm when DHT_TOPIC is set in .env - if (CONFIG.DHT_TOPIC) { - await startDHT(con, CONFIG.DHT_TOPIC) - } - // Express Server const app = express()