Cosmos-Server/client/src/api/index.jsx

57 lines
1 KiB
React
Raw Normal View History

2023-04-28 18:28:01 +00:00
import * as auth from './authentication';
import * as users from './users';
import * as config from './config';
import * as docker from './docker';
2023-03-29 20:38:50 +00:00
import wrap from './wrap';
const getStatus = () => {
return wrap(fetch('/cosmos/api/status', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}))
}
2023-04-28 18:28:01 +00:00
const isOnline = () => {
return fetch('/cosmos/api/status', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}).then(async (response) => {
let rep;
try {
rep = await response.json();
} catch {
throw new Error('Server error');
}
if (response.status == 200) {
return rep;
}
const e = new Error(rep.message);
e.status = response.status;
throw e;
});
}
2023-03-29 20:38:50 +00:00
const newInstall = (req) => {
return wrap(fetch('/cosmos/api/newInstall', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
}))
}
2023-03-12 18:17:28 +00:00
export {
2023-03-13 00:49:27 +00:00
auth,
2023-03-16 18:56:36 +00:00
users,
2023-03-25 20:15:00 +00:00
config,
2023-03-29 20:38:50 +00:00
docker,
getStatus,
newInstall,
2023-04-28 18:28:01 +00:00
isOnline
2023-03-12 18:17:28 +00:00
};