-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.ts
48 lines (44 loc) · 1.25 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import apiBuilder from './api/index.js'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import envPaths from 'env-paths'
import { IPFSProvider, BUILTIN } from './protocols/ipfs.js'
const paths = envPaths('distributed-press')
const argv = yargs(hideBin(process.argv)).options({
port: { type: 'number' },
dnsport: { type: 'number' },
host: { type: 'string' },
domain: { type: 'string' },
data: { type: 'string' },
ipfsProvider: { type: 'string' }
}).parseSync()
export interface ServerI {
port: number
dnsport: number
host: string
domain: string
storage: string
ipfsProvider: IPFSProvider
}
const cfg: ServerI = {
port: Number(argv.port ?? process.env.PORT ?? '8080'),
dnsport: Number(argv.dnsport ?? process.env.DNSPORT ?? '53'),
host: argv.host ?? process.env.HOST ?? 'localhost',
domain: argv.domain ?? process.env.DOMAIN ?? 'localhost',
storage: argv.data ?? paths.data,
ipfsProvider: (argv.ipfsProvider as IPFSProvider) ?? BUILTIN
}
const server = await apiBuilder({
...cfg,
useLogging: true,
useSwagger: true,
usePrometheus: true,
useSigIntHandler: true,
useWebringDirectoryListing: true
})
server.listen(cfg, (err, _address) => {
if (err != null) {
server.log.error(err)
process.exit(1)
}
})