Makes healthcheck data a server polling thing.
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
import { type ServiceHandler } from '../service';
|
||||
import type { ServiceConfig } from '$lib/config';
|
||||
import { type ServiceData, type ServiceHandler } from '../service';
|
||||
|
||||
export const handle: ServiceHandler = ({ fetch, config }) => {
|
||||
const url = config.url + '/api.php?summaryRaw&auth=' + config.api_token;
|
||||
|
||||
return {
|
||||
logo: 'https://cdn.rawgit.com/pi-hole/graphics/master/Vortex/Vortex.svg',
|
||||
raw: fetch(url).then((raw) => raw.json()),
|
||||
url: url
|
||||
export const handle: ServiceHandler = async (config: ServiceConfig) => {
|
||||
const res: ServiceData = {
|
||||
logo: 'https://cdn.rawgit.com/pi-hole/graphics/master/Vortex/Vortex.svg'
|
||||
};
|
||||
|
||||
try {
|
||||
const resp: Response = await fetch(
|
||||
config.url + '/api.php?summaryRaw&auth=' + config.api_token
|
||||
);
|
||||
res.status = resp.ok ? 'online' : 'offline';
|
||||
res.raw = resp.json();
|
||||
} catch (error) {
|
||||
res.status = undefined;
|
||||
console.warn('could not fetch pihole status: ' + error);
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user