@@ -57,24 +57,26 @@ function applyDefaults (ipfsd) {
57
57
writeConfigFile ( ipfsd , config )
58
58
}
59
59
60
- function getGatewayPort ( config ) {
61
- let gatewayUrl = null
60
+ const getRpcApiPort = ( config ) => getHttpPort ( config . Addresses . API )
61
+ const getGatewayPort = ( config ) => getHttpPort ( config . Addresses . Gateway )
62
+ function getHttpPort ( addrs ) {
63
+ let httpUrl = null
62
64
63
- if ( Array . isArray ( config . Addresses . Gateway ) ) {
64
- gatewayUrl = config . Addresses . Gateway . find ( v => v . includes ( '127.0.0.1' ) )
65
+ if ( Array . isArray ( addrs ) ) {
66
+ httpUrl = addrs . find ( v => v . includes ( '127.0.0.1' ) )
65
67
} else {
66
- gatewayUrl = config . Addresses . Gateway
68
+ httpUrl = addrs
67
69
}
68
70
69
- const gw = parseCfgMultiaddr ( gatewayUrl )
71
+ const gw = parseCfgMultiaddr ( httpUrl )
70
72
return gw . nodeAddress ( ) . port
71
73
}
72
74
73
75
// Apply one-time updates to the config of IPFS node.
74
76
// This is the place where we execute fixes and performance tweaks for existing users.
75
77
function migrateConfig ( ipfsd ) {
76
78
// Bump revision number when new migration rule is added
77
- const REVISION = 2
79
+ const REVISION = 3
78
80
const REVISION_KEY = 'daemonConfigRevision'
79
81
const CURRENT_REVISION = store . get ( REVISION_KEY , 0 )
80
82
@@ -92,7 +94,7 @@ function migrateConfig (ipfsd) {
92
94
return
93
95
}
94
96
95
- if ( CURRENT_REVISION <= 0 ) {
97
+ if ( CURRENT_REVISION < 1 ) {
96
98
// Cleanup https://github.com/ipfs-shipyard/ipfs-desktop/issues/1631
97
99
if ( config . Discovery && config . Discovery . MDNS && config . Discovery . MDNS . enabled ) {
98
100
config . Discovery . MDNS . Enabled = config . Discovery . MDNS . Enabled || true
@@ -101,7 +103,7 @@ function migrateConfig (ipfsd) {
101
103
}
102
104
}
103
105
104
- if ( CURRENT_REVISION <= 1 ) {
106
+ if ( CURRENT_REVISION < 3 ) {
105
107
const api = config . API || { }
106
108
const httpHeaders = api . HTTPHeaders || { }
107
109
const accessControlAllowOrigin = httpHeaders [ 'Access-Control-Allow-Origin' ] || [ ]
@@ -117,7 +119,11 @@ function migrateConfig (ipfsd) {
117
119
const addedWebUI = addURL ( 'https://webui.ipfs.io' )
118
120
const addedGw = addURL ( `http://webui.ipfs.io.ipns.localhost:${ getGatewayPort ( config ) } ` )
119
121
120
- if ( addedWebUI || addedGw ) {
122
+ // https://github.com/ipfs/ipfs-companion/issues/1068 in go-ipfs <0.13
123
+ // TODO: remove addedApiPort after go-ipfs 0.13 ships
124
+ const addedApiPort = addURL ( `http://127.0.0.1:${ getRpcApiPort ( config ) } ` )
125
+
126
+ if ( addedWebUI || addedGw || addedApiPort ) {
121
127
httpHeaders [ 'Access-Control-Allow-Origin' ] = accessControlAllowOrigin
122
128
api . HTTPHeaders = httpHeaders
123
129
config . API = api
0 commit comments