-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
37 lines (32 loc) · 849 Bytes
/
cli.js
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
#!/usr/bin/env node
var minimist = require('minimist')
var http = require('http')
var Archiver = require('hypercore-archiver')
var archiverServer = require('.')
var argv = minimist(process.argv.slice(2), {
alias: {
httpPort: 'p'
},
default: {
httpPort: process.env.PORT || 8080,
datPort: 3282,
archiveDir: 'dats',
swarm: true,
http: true
},
boolean: ['swarm', 'http']
})
var archiver = Archiver(argv.archiveDir)
var datServer = archiverServer(archiver, argv)
if (argv.http) {
var server = http.createServer()
server.on('request', datServer.httpRequest)
server.listen(argv.httpPort, function () {
console.log('Server is listening on port ' + argv.httpPort)
})
}
if (argv.swarm) {
datServer.swarm.on('listening', function () {
console.log('Listening for connections on the Dat Network')
})
}