-
-
Save kvasdopil/d6739a6d127d8c1ed6e97e73e2d42524 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (backendUrl, currentUrl) => { | |
return new Promise((resolve, reject) => { | |
get(backendUrl) | |
.then(response => { | |
if (response.status !== 200) { | |
reject(new Error(response.status)); | |
return; | |
} | |
const parseJs = JSON.parse(response.data); | |
const checkLoad = Promise.all(parseJs.map(element => { | |
return get(`${element.url}/status`).then(response => JSON.parse(response.data)); | |
})) | |
.then(response => response.sort((a, b) => a.workload > b.workload)) | |
.then(response => post(currentUrl, {value: response[0].url})) | |
.then(response => { | |
if (response.status !== 201) { | |
reject(new Error(response.status)); | |
return; | |
} | |
resolve(response); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment