fix ping status

This commit is contained in:
Matthias Kretschmann 2021-09-14 15:44:12 +02:00
parent 0a8f384e21
commit baec08c0a9
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 8 additions and 5 deletions

View File

@ -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])

View File

@ -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) {