Skip to content

Commit

Permalink
fix: return gateway maddr in .info response
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Nov 14, 2024
1 parent 3574412 commit d4cbc60
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/kubo/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class KuboDaemon implements KuboNode {
private readonly disposable: boolean
private subprocess?: ResultPromise
private _api?: KuboRPCClient
private _gateway?: string
private readonly repo: string
private readonly stdout: Logger
private readonly stderr: Logger
Expand Down Expand Up @@ -91,7 +92,8 @@ export default class KuboDaemon implements KuboNode {
peerId: id?.id.toString(),
multiaddrs: (id?.addresses ?? []).map(ma => ma.toString()),
api: checkForRunningApi(this.repo),
repo: this.repo
repo: this.repo,
gateway: this._gateway ?? ''
}
}

Expand Down Expand Up @@ -202,11 +204,16 @@ export default class KuboDaemon implements KuboNode {
const readyHandler = (data: Buffer): void => {
output += data.toString()
const apiMatch = output.trim().match(/API .*listening on:? (.*)/)
const gwMatch = output.trim().match(/Gateway .*listening on:? (.*)/)

if ((apiMatch != null) && apiMatch.length > 0) {
this._api = this.options.rpc(apiMatch[1])
}

if ((gwMatch != null) && gwMatch.length > 0) {
this._gateway = gwMatch[1]
}

if (output.match(/(?:daemon is running|Daemon is ready)/) != null) {
// we're good
stdout.off('data', readyHandler)
Expand Down
1 change: 1 addition & 0 deletions src/kubo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface KuboInfo {
multiaddrs: string[]
api?: string
repo: string
gateway: string
}

export interface KuboNode extends Node<KuboRPCClient, KuboOptions, KuboInfo, KuboInitOptions, KuboStartOptions, KuboStopOptions> {
Expand Down
21 changes: 21 additions & 0 deletions test/controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,25 @@ describe('Node API', function () {
}
})
})

describe('info', () => {
describe('should return the node info', () => {
for (const opts of types) {
it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => {
const node = await factory.spawn(opts)
const info = await node.info()

expect(info).to.have.property('version').that.is.a('string')
expect(info).to.have.property('api').that.is.a('string')
expect(info).to.have.property('peerId').that.is.a('string')
expect(info).to.have.property('repo').that.is.a('string')
expect(info).to.have.property('pid').that.is.a('number')
expect(info).to.have.property('multiaddrs').that.is.an('array')
expect(info).to.have.property('gateway').that.is.a('string').that.matches(/\/ip4\/127\.0\.0\.1\/tcp\/\d+/)

await node.stop()
})
}
})
})
})
2 changes: 2 additions & 0 deletions test/endpoint/routes.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ describe('routes', function () {
expect(res.result).to.have.property('api').that.is.a('string')
expect(res.result).to.have.property('repo').that.is.a('string')
expect(res.result).to.have.property('multiaddrs').that.is.an('array')
expect(res.result).to.have.property('peerId').that.is.a('string')
expect(res.result).to.have.property('gateway').that.is.a('string')
})

it('should return 400', async () => {
Expand Down

0 comments on commit d4cbc60

Please sign in to comment.