mirror of
https://github.com/kremalicious/ipfs.git
synced 2024-11-23 10:27:10 +01:00
fix ping status
This commit is contained in:
parent
0a8f384e21
commit
baec08c0a9
@ -11,9 +11,9 @@ export default function Status({ type }: { type: string }): ReactElement {
|
||||
const url =
|
||||
type === 'gateway'
|
||||
? `${ipfsGateway}/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme`
|
||||
: `${ipfsNodeUri}/api/v0/id`
|
||||
|
||||
const ping = await pingUrl(url)
|
||||
: `${ipfsNodeUri}/api/v0/version`
|
||||
const method = type === 'gateway' ? 'get' : 'post'
|
||||
const ping = await pingUrl(url, method)
|
||||
setIsLoading(false)
|
||||
setIsOnline(ping)
|
||||
}, [type])
|
||||
|
@ -9,9 +9,12 @@ export function formatBytes(a: number, b: number): string {
|
||||
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
|
||||
}
|
||||
|
||||
export async function pingUrl(url: string): Promise<boolean> {
|
||||
export async function pingUrl(
|
||||
url: string,
|
||||
method?: 'get' | 'post'
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
const response = await axios(url, { timeout: 5000 })
|
||||
const response = await axios[method || 'get'](url, { timeout: 5000 })
|
||||
if (!response || response.status !== 200) return false
|
||||
return true
|
||||
} catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user