2022-06-14 21:29:47 +02:00
|
|
|
import {IpldStore} from '@adxp/common'
|
|
|
|
import PDSServer from '@adxp/server/dist/server.js'
|
|
|
|
import PDSDatabase from '@adxp/server/dist/db/index.js'
|
|
|
|
import WSRelayServer from '@adxp/ws-relay/dist/index.js'
|
2022-07-18 22:24:37 +02:00
|
|
|
import AuthLobbyServer from '@adxp/auth-lobby'
|
2022-06-10 18:55:09 +02:00
|
|
|
|
2022-06-14 21:29:47 +02:00
|
|
|
const PDS_PORT = 2583
|
2022-07-18 22:24:37 +02:00
|
|
|
const AUTH_LOBBY1_PORT = 3001
|
|
|
|
const AUTH_LOBBY2_PORT = 3002
|
2022-06-14 21:29:47 +02:00
|
|
|
const WSR_PORT = 3005
|
2022-06-10 18:55:09 +02:00
|
|
|
|
|
|
|
async function start() {
|
|
|
|
console.log('Initializing...')
|
|
|
|
|
2022-06-14 21:29:47 +02:00
|
|
|
const db = PDSDatabase.memory()
|
2022-06-10 18:55:09 +02:00
|
|
|
const serverBlockstore = IpldStore.createInMemory()
|
|
|
|
await db.dropTables()
|
|
|
|
await db.createTables()
|
2022-06-14 21:29:47 +02:00
|
|
|
PDSServer(serverBlockstore, db, PDS_PORT)
|
|
|
|
|
2022-07-18 22:24:37 +02:00
|
|
|
init(AuthLobbyServer, AUTH_LOBBY1_PORT, 'Auth lobby')
|
|
|
|
|
2022-06-14 21:29:47 +02:00
|
|
|
if (process.argv.includes('--relay')) {
|
2022-07-18 22:24:37 +02:00
|
|
|
init(AuthLobbyServer, AUTH_LOBBY2_PORT, 'Auth lobby 2')
|
|
|
|
init(WSRelayServer, WSR_PORT, 'Relay server')
|
2022-06-14 21:29:47 +02:00
|
|
|
} else {
|
2022-07-18 22:24:37 +02:00
|
|
|
console.log('Include --relay to start the WS Relay and second auth lobby')
|
2022-06-14 21:29:47 +02:00
|
|
|
}
|
2022-06-10 18:55:09 +02:00
|
|
|
}
|
|
|
|
start()
|
2022-07-18 22:24:37 +02:00
|
|
|
|
|
|
|
function init(fn, port, name) {
|
|
|
|
const s = fn(port)
|
|
|
|
s.on('listening', () => console.log(`✔ ${name} running on port ${port}`))
|
|
|
|
s.on('error', e => console.log(`${name} failed to start:`, e))
|
|
|
|
}
|