podcast manager
at push-pqtlwkromqlk 60 lines 1.5 kB view raw
1import {dirname, join} from 'path' 2import {fileURLToPath} from 'url' 3import {parseArgs} from 'util' 4 5import {ensureRealmMap} from '#realm/server/state' 6import {buildServer} from '#server/index' 7 8const __filename = fileURLToPath(import.meta.url) 9const __dirname = dirname(__filename) 10 11const args = parseArgs({ 12 args: process.argv.slice(2), 13 options: { 14 port: {type: 'string', default: '4001'}, 15 host: {type: 'string', default: '127.0.0.1'}, 16 }, 17}) 18 19const port = parseInt(args.values.port) 20const host = args.values.host 21const root = join(__dirname, '../../dist') 22 23const server = buildServer(root) 24const realms = await ensureRealmMap() 25 26async function handleExit(code: number) { 27 for (const realm of realms.values()) { 28 console.log(` closing realm: ${realm.realmid}: ${realm.storage.identities.size}`) 29 await realm.storage.close() 30 } 31 32 console.log(` kthxbye`) 33 process.exit(code) 34} 35 36server.listen(port, host, () => { 37 console.log(` 38 skypod ⚡️ http://${host}:${port} 39 `) 40 41 for (const realm of realms.values()) { 42 console.log(` realm: ${realm.realmid}, idents: ${realm.storage.identities.size}`) 43 } 44}) 45 46process.on('SIGTERM', () => { 47 console.log('SIGTERM: Exiting...') 48 handleExit(0).catch((ex: unknown) => { 49 console.error('error during shutdown, goodbye', ex) 50 process.exit(1) 51 }) 52}) 53 54process.on('SIGINT', () => { 55 console.log('SIGINT: Exiting...') 56 handleExit(0).catch((ex: unknown) => { 57 console.error('error during shutdown, goodbye', ex) 58 process.exit(1) 59 }) 60})