-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(issue-1852): now supports multiple api and gateways #1903
feat(issue-1852): now supports multiple api and gateways #1903
Conversation
9ee14bb
to
57bf1cf
Compare
I think I need some guidance on how to get these tests passing. I have tried a bunch of different things and I am not sure what I need to do to get things to work. |
License: MIT Signed-off-by: Grant Herman [email protected]
87918d7
to
b5c7628
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @grantlouisherman thanks for your contribution! Lots of minor feedback 🙏 but this PR is great! Do you think you could address the feedback and then if the tests are still failing I can help you to resolve the issues? 🚀 ⭐️
src/http/index.js
Outdated
@@ -29,6 +29,24 @@ function hapiInfoToMultiaddr (info) { | |||
return toMultiaddr(uri) | |||
} | |||
|
|||
async function serverCreator (serverAddrsArr, createServerFunc, hapiInfoToMultiaddr, ipfs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to pass hapiInfoToMultiaddr
, it is in scope
src/http/index.js
Outdated
@@ -29,6 +29,24 @@ function hapiInfoToMultiaddr (info) { | |||
return toMultiaddr(uri) | |||
} | |||
|
|||
async function serverCreator (serverAddrsArr, createServerFunc, hapiInfoToMultiaddr, ipfs) { | |||
if (!serverAddrsArr.length) { | |||
debug(Error('There are no addresses')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just return []
here instead - it shouldn't be an error to not have any addresses to listen on.
src/http/index.js
Outdated
@@ -29,6 +29,24 @@ function hapiInfoToMultiaddr (info) { | |||
return toMultiaddr(uri) | |||
} | |||
|
|||
async function serverCreator (serverAddrsArr, createServerFunc, hapiInfoToMultiaddr, ipfs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can we rename serverAddrsArr
to just serverAddrs
and then add a check as the first line of this function to convert it to an array if it is not already:
serverAddrs = Array.isArray(serverAddrs) ? serverAddrs : [serverAddrs]
src/http/index.js
Outdated
@@ -29,6 +29,24 @@ function hapiInfoToMultiaddr (info) { | |||
return toMultiaddr(uri) | |||
} | |||
|
|||
async function serverCreator (serverAddrsArr, createServerFunc, hapiInfoToMultiaddr, ipfs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can we rename createServerFunc
to createServer
? By convention we don't add type information to our variable names in this project.
src/http/index.js
Outdated
debug(Error('There are no addresses')) | ||
} | ||
// just in case the address is just string | ||
let serversAddrs = [].concat(serverAddrsArr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed if we add the check as suggested above.
src/http/index.js
Outdated
ipfs._print('Web UI available at %s', toUri(apiServer.info.ma) + '/webui') | ||
this._gatewayServer = await Promise.resolve( | ||
serverCreator.apply(this, [gatewayAddr, this._createGatewayServer, hapiInfoToMultiaddr, ipfs]) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please rename to this._gatewayServers
and just await the result:
this._gatewayServer = await serverCreator(gatewayAddrs, this._createGatewayServer, ipfs)
src/http/index.js
Outdated
} | ||
|
||
async stop () { | ||
function stopServer (serverArr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename stopServer
-> stopServers
and serverArr
to servers
.
src/http/index.js
Outdated
function stopServer (serverArr) { | ||
for (let i = 0; i < serverArr.length; i++) { | ||
serverArr[i].stop() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to return a promise from this function:
function stopServers (servers) {
return Promise.all(servers.map(server => server.stop()))
}
src/http/index.js
Outdated
this._log('stopping') | ||
await Promise.all([ | ||
this._apiServer && this._apiServer.stop(), | ||
this._gatewayServer && this._gatewayServer.stop(), | ||
this._apiServer && stopServer(this._apiServer), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._apiServer && stopServer(this._apiServer), | |
stopServers(this._apiServers), |
src/http/index.js
Outdated
this._apiServer && this._apiServer.stop(), | ||
this._gatewayServer && this._gatewayServer.stop(), | ||
this._apiServer && stopServer(this._apiServer), | ||
this._gatewayServer && stopServer(this._gatewayServer), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._gatewayServer && stopServer(this._gatewayServer), | |
stopServers(this._gatewayServer), |
Hey @alanshaw I addressed your PR comments and left them in their own commit message. Once that looks good I can squash that commit. |
d05964f
to
8077d30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great ❤️, all we need now is a test to check we can configure multiple API and Gateway servers.
src/http/index.js
Outdated
@@ -29,6 +29,22 @@ function hapiInfoToMultiaddr (info) { | |||
return toMultiaddr(uri) | |||
} | |||
|
|||
async function serverCreator (serverAddrs, createServer, hapiInfoToMultiaddr, ipfs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to pass hapiInfoToMultiaddr to this function - it’s in scope already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey when I don't pass that in and when I run jsipfs daemon
it throws an error saying that it is not a function. Not 100% sure why, but I kept it in there for that reason. Maybe because it is being called within the scope of the start function that it does not have access to that function?
8077d30
to
1b17688
Compare
test/cli/daemon.js
Outdated
@@ -91,6 +91,33 @@ describe('daemon', () => { | |||
}).catch(err => done(err)) | |||
}) | |||
|
|||
skipOnWindows('should handle API Array and Gateway Array', function (done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @alanshaw I'm not sure if you wanted this to be tested in another location as well.
License: MIT Signed-off-by: Alan Shaw <[email protected]>
License: MIT Signed-off-by: Alan Shaw <[email protected]>
@grantlouisherman hope you don't mind I added a test and cleaned up some of the code to make it a bit more robust to undefined values etc. Tests are passing locally for me, I'll just wait for CI and then this'll be ready to merge. Thanks again! ⭐️ |
License: MIT Signed-off-by: Alan Shaw <[email protected]>
thanks @alanshaw for your help. I am going to try and pull another ticket if thats cool |
resolves #1852
License: MIT
Signed-off-by: Grant Herman [email protected]