@@ -5,6 +5,8 @@ const Pino = require('hapi-pino')
5
5
const debug = require ( 'debug' )
6
6
const multiaddr = require ( 'multiaddr' )
7
7
const promisify = require ( 'promisify-es6' )
8
+ const toUri = require ( 'multiaddr-to-uri' )
9
+ const toMultiaddr = require ( 'uri-to-multiaddr' )
8
10
9
11
const IPFS = require ( '../core' )
10
12
const WStar = require ( 'libp2p-webrtc-star' )
@@ -14,9 +16,17 @@ const WS = require('libp2p-websockets')
14
16
const Bootstrap = require ( 'libp2p-bootstrap' )
15
17
const errorHandler = require ( './error-handler' )
16
18
17
- function uriToMultiaddr ( uri ) {
18
- const ipPort = uri . split ( '/' ) [ 2 ] . split ( ':' )
19
- return `/ip4/${ ipPort [ 0 ] } /tcp/${ ipPort [ 1 ] } `
19
+ function hapiInfoToMultiaddr ( info ) {
20
+ let hostname = info . host
21
+ let uri = info . uri
22
+ // ipv6 fix
23
+ if ( hostname . includes ( ':' ) && ! hostname . startsWith ( '[' ) ) {
24
+ // hapi 16 produces invalid URI for ipv6
25
+ // we fix it here by restoring missing square brackets
26
+ hostname = `[${ hostname } ]`
27
+ uri = uri . replace ( `://${ info . host } ` , `://${ hostname } ` )
28
+ }
29
+ return toMultiaddr ( uri )
20
30
}
21
31
22
32
class HttpApi {
@@ -82,7 +92,7 @@ class HttpApi {
82
92
const apiAddr = config . Addresses . API . split ( '/' )
83
93
const apiServer = await this . _createApiServer ( apiAddr [ 2 ] , apiAddr [ 4 ] , ipfs )
84
94
await apiServer . start ( )
85
- apiServer . info . ma = uriToMultiaddr ( apiServer . info . uri )
95
+ apiServer . info . ma = hapiInfoToMultiaddr ( apiServer . info )
86
96
this . _apiServer = apiServer
87
97
88
98
// for the CLI to know the where abouts of the API
@@ -91,12 +101,12 @@ class HttpApi {
91
101
const gatewayAddr = config . Addresses . Gateway . split ( '/' )
92
102
const gatewayServer = await this . _createGatewayServer ( gatewayAddr [ 2 ] , gatewayAddr [ 4 ] , ipfs )
93
103
await gatewayServer . start ( )
94
- gatewayServer . info . ma = uriToMultiaddr ( gatewayServer . info . uri )
104
+ gatewayServer . info . ma = hapiInfoToMultiaddr ( gatewayServer . info )
95
105
this . _gatewayServer = gatewayServer
96
106
97
107
ipfs . _print ( 'API listening on %s' , apiServer . info . ma )
98
108
ipfs . _print ( 'Gateway (read only) listening on %s' , gatewayServer . info . ma )
99
- ipfs . _print ( 'Web UI available at %s' , apiServer . info . uri + '/webui' )
109
+ ipfs . _print ( 'Web UI available at %s' , toUri ( apiServer . info . ma ) + '/webui' )
100
110
this . _log ( 'started' )
101
111
return this
102
112
}
0 commit comments