[FIX] GET /info to check if it's a valid server instead of x-instance-id (#573)
This commit is contained in:
parent
73feb4f067
commit
5ee1f557d8
|
@ -1,6 +1,5 @@
|
||||||
import { AsyncStorage, Platform } from 'react-native';
|
import { AsyncStorage, Platform } from 'react-native';
|
||||||
import foreach from 'lodash/forEach';
|
import foreach from 'lodash/forEach';
|
||||||
import RNFetchBlob from 'rn-fetch-blob';
|
|
||||||
import * as SDK from '@rocket.chat/sdk';
|
import * as SDK from '@rocket.chat/sdk';
|
||||||
|
|
||||||
import reduxStore from './createStore';
|
import reduxStore from './createStore';
|
||||||
|
@ -78,15 +77,11 @@ const RocketChat = {
|
||||||
console.warn(`AsyncStorage error: ${ error.message }`);
|
console.warn(`AsyncStorage error: ${ error.message }`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_hasInstanceId(headers) {
|
async testServer(server) {
|
||||||
return !!headers[Object.keys(headers).find(item => item.toLowerCase() === 'x-instance-id')];
|
|
||||||
},
|
|
||||||
async testServer(url) {
|
|
||||||
try {
|
try {
|
||||||
let response = await RNFetchBlob.fetch('HEAD', url);
|
const result = await fetch(`${ server }/api/v1/info`).then(response => response.json());
|
||||||
response = response.respInfo;
|
if (result.success && result.info) {
|
||||||
if (response.status === 200 && RocketChat._hasInstanceId(response.headers)) {
|
return server;
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('testServer', e);
|
log('testServer', e);
|
||||||
|
|
Loading…
Reference in New Issue