refactor server
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
ale 2024-11-10 02:36:04 +01:00
parent 6c56252145
commit 5deb70a0b0
2 changed files with 47 additions and 41 deletions

View File

@ -238,5 +238,5 @@ module.exports = async (client, apex, app) => {
job = schedule.scheduleJob('0 ' + constant.schedule + ' * * *', async () => {
await util.sendFederatedMessage(constant.nick, null, 'Scanning ' + app.locals.server + ' instance with ' + app.locals.scantotal + ' peers\nScanned ' + app.locals.peers + ' peers from ' + app.locals.instances + ' instances, ' + app.locals.created + ' created, ' + app.locals.updated + ' updated\nhttps://' + constant.apexdomain)
})
await scanReturn()
return await scanReturn()
}

View File

@ -54,21 +54,7 @@ const apexinstance = require('./lib/apex'),
},
itemsPerPage: 200
}),
server = http.createServer(app).listen(4000, () => {
mongoclient.connect()
.then(async () => {
const exists = await client.indices.exists({ index: constant.index })
if (!exists) {
await client.indices.create({
index: constant.index,
body: require('./fediblock-mapping.json')
})
}
apex.store.db = mongoclient.db(constant.dbname)
return apex.store.db
})
.then(async () => {
try {
register = async () => {
const admin = await apex.store.getObject(apex.utils.usernameToIRI('admin'), true)
if (!admin) {
const adminaccount = await apex.createActor('admin', 'Fediblock Admin', 'Fediblock Admin - https://' + constant.apexdomain,
@ -108,6 +94,23 @@ const apexinstance = require('./lib/apex'),
} else {
apex.systemUser = admin
}
},
connect = () => {
mongoclient.connect()
.then(async () => {
const exists = await client.indices.exists({ index: constant.index })
if (!exists) {
await client.indices.create({
index: constant.index,
body: require('./fediblock-mapping.json')
})
}
apex.store.db = mongoclient.db(constant.dbname)
return apex.store.db
})
.then(async () => {
try {
await register()
taskdeletedup(client)
await apex.startDelivery()
console.log('Server listening on ' + server.address().address + ':' + server.address().port)
@ -116,6 +119,9 @@ const apexinstance = require('./lib/apex'),
console.error(e)
}
})
},
server = http.createServer(app).listen(4000, () => {
connect()
})
app.locals.scan = new events.EventEmitter()