Next.js+React web interface for controlling HAProxy clusters (groups of servers), in conjunction with with https://gitgud.io/fatchan/haproxy-protection.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
641 B
28 lines
641 B
import NProgress from 'nprogress';
|
|
|
|
export default async function ApiCall(route, method, body, stateCallback, finishProgress) {
|
|
try {
|
|
const options = {
|
|
method,
|
|
};
|
|
if (body != null) {
|
|
options.body = body;
|
|
options.headers = { 'Content-Type': 'application/json' };
|
|
}
|
|
console.log(options)
|
|
NProgress.start();
|
|
let response = await fetch(route, options)
|
|
.then(res => res.json());
|
|
console.log(response)
|
|
stateCallback && stateCallback(response);
|
|
} catch(e) {
|
|
console.error(e);
|
|
} finally {
|
|
if (finishProgress != null) {
|
|
NProgress.set(finishProgress);
|
|
} else {
|
|
NProgress.done(true);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|