Skip to content

Commit 24b870b

Browse files
authored
feat: add isGateway method (#1046)
1 parent a24ef4a commit 24b870b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/bee.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,18 @@ export class Bee {
12821282
return true
12831283
}
12841284

1285+
/**
1286+
* Checks the `/gateway` endpoint to see if the remote API is a gateway.
1287+
*
1288+
* Do note that this is not a standard way to check for gateway nodes,
1289+
* but some of the gateway tooling expose this endpoint.
1290+
*
1291+
* @param options
1292+
*/
1293+
async isGateway(options?: BeeRequestOptions): Promise<boolean> {
1294+
return status.isGateway(this.getRequestOptionsForCall(options))
1295+
}
1296+
12851297
// Legacy debug API
12861298

12871299
async getNodeAddresses(options?: BeeRequestOptions): Promise<NodeAddresses> {

src/modules/status.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Types } from 'cafe-utility'
12
import { BeeRequestOptions } from '../index'
23
import { http } from '../utils/http'
34

@@ -11,3 +12,15 @@ export async function checkConnection(requestOptions: BeeRequestOptions): Promis
1112
url: '',
1213
})
1314
}
15+
16+
export async function isGateway(requestOptions: BeeRequestOptions): Promise<boolean> {
17+
try {
18+
const response = await http<unknown>(requestOptions, {
19+
url: '/gateway',
20+
})
21+
const data = Types.asObject(response.data)
22+
return Types.asBoolean(data.gateway)
23+
} catch (error) {
24+
return false
25+
}
26+
}

0 commit comments

Comments
 (0)