DNS support (#56)

* feat: dns support
This commit is contained in:
David Dias
2017-03-23 15:09:06 +00:00
committed by GitHub
parent ec467377e6
commit bdfd042ace
6 changed files with 173 additions and 45 deletions

22
src/ma-to-url.js Normal file
View File

@ -0,0 +1,22 @@
'use strict'
const multiaddr = require('multiaddr')
function maToUrl (ma) {
const maStrSplit = ma.toString().split('/')
const proto = ma.protos()[2].name
if (!(proto === 'ws' || proto === 'wss')) {
throw new Error('invalid multiaddr' + ma.toString())
}
let url = ma.protos()[2].name + '://' + maStrSplit[2]
if (!multiaddr.isName(ma)) {
url += ':' + maStrSplit[4]
}
return url
}
module.exports = maToUrl