mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-17 02:09:49 +00:00
refactor widget api design
this passes all widget API calls through the backend, with a pluggable design and reusable API handlers
This commit is contained in:
parent
975f79f6cc
commit
97bf174b78
27 changed files with 370 additions and 252 deletions
|
@ -3,21 +3,12 @@ import useSWR from "swr";
|
|||
import Widget from "../widget";
|
||||
import Block from "../block";
|
||||
|
||||
import { formatApiUrl } from "utils/api-helpers";
|
||||
|
||||
export default function Pihole({ service }) {
|
||||
const config = service.widget;
|
||||
|
||||
function buildApiUrl(endpoint) {
|
||||
const { url, proxy } = config;
|
||||
|
||||
if (proxy) {
|
||||
const fullUrl = `${url}/admin/${endpoint}`;
|
||||
return "/api/proxy?url=" + encodeURIComponent(fullUrl);
|
||||
}
|
||||
|
||||
return `${url}/admin/${endpoint}`;
|
||||
}
|
||||
|
||||
const { data: piholeData, error: piholeError } = useSWR(buildApiUrl("api.php"));
|
||||
const { data: piholeData, error: piholeError } = useSWR(formatApiUrl(config, "api.php"));
|
||||
|
||||
if (piholeError) {
|
||||
return <Widget error="PiHole API Error" />;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue