forked from RangerMauve/hyperswarm-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
30 lines (19 loc) · 795 Bytes
/
bin.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
#!/usr/bin/env node
const HyperswarmServer = require('./server')
const http = require('http')
const send = require('send')
const path = require('path')
const argv = require('minimist')(process.argv.slice(2))
const DEFAULT_PORT = 4977 // HYPR on a cellphone keypad
const INDEX_HTML_LOCATION = path.join(__dirname, 'index.html')
const server = http.createServer(function onRequest (req, res) {
send(req, INDEX_HTML_LOCATION)
.pipe(res)
})
const wsServer = new HyperswarmServer()
wsServer.listenOnServer(server)
const port = argv.port ? parseInt(argv.port, 10) : DEFAULT_PORT
console.log(`Listening on ws://localhost:${port}`)
console.log(`-> Proxy available on ws://localhost:${port}/proxy`)
console.log(`-> Signal available on ws://localhost:${port}/signal`)
server.listen(port)