move DHT connection into main

This commit is contained in:
Moriz Wahl 2022-11-07 12:45:44 +01:00
parent 51cc3164b2
commit 8aac319895
3 changed files with 11 additions and 10 deletions

View File

@ -21,7 +21,10 @@ const nodeAPI = {
API_2_00: `${nodeURL}/graphql/2_00/`,
}
export const startDHT = async (connection: Connection, topic: string): Promise<void> => {
export const startDHT = async (
connection: Connection,
topic: string,
): Promise<void> => {
try {
const TOPIC = DHT.hash(Buffer.from(topic))

View File

@ -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) => {

View File

@ -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()