Added API tests + added vitest.config.ts + added fallback of window.fetch with xmlhttprequest
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
0bf6b173f4
commit
05e9013c3b
8 changed files with 64 additions and 85 deletions
27
src/App.tsx
27
src/App.tsx
|
@ -240,15 +240,28 @@ class App extends React.Component<IAppProps> {
|
|||
* Fetch the configuration from the API
|
||||
* @returns {Configation} The model of the configuration for the application
|
||||
*/
|
||||
async function fetchConfiguration(): Promise<Configuration> {
|
||||
export async function fetchConfiguration(): Promise<Configuration> {
|
||||
const url = `${import.meta.env.VITE_API_URL}`;
|
||||
|
||||
return await fetch(url, {
|
||||
method: 'POST'
|
||||
})
|
||||
.then((response) =>
|
||||
response.json()
|
||||
) as Configuration;
|
||||
if (window.fetch) {
|
||||
return await fetch(url, {
|
||||
method: 'POST'
|
||||
})
|
||||
.then((response) =>
|
||||
response.json()
|
||||
) as Configuration;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', url, true);
|
||||
xhr.onreadystatechange = function() { // Call a function when the state changes.
|
||||
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
|
||||
resolve(JSON.parse(this.responseText));
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue