mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 07:18:47 +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,39 +3,12 @@ import useSWR from "swr";
|
|||
import Widget from "../widget";
|
||||
import Block from "../block";
|
||||
|
||||
import { formatApiUrl } from "utils/api-helpers";
|
||||
|
||||
export default function Npm({ service }) {
|
||||
const config = service.widget;
|
||||
const { url } = config;
|
||||
|
||||
const fetcher = async (reqUrl) => {
|
||||
const { url, username, password } = config;
|
||||
const loginUrl = `${url}/api/tokens`;
|
||||
const body = { identity: username, secret: password };
|
||||
|
||||
const res = await fetch(loginUrl, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(
|
||||
async (data) =>
|
||||
await fetch(reqUrl, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + data.token,
|
||||
},
|
||||
})
|
||||
);
|
||||
return res.json();
|
||||
};
|
||||
|
||||
const { data: infoData, error: infoError } = useSWR(`${url}/api/nginx/proxy-hosts`, fetcher);
|
||||
|
||||
console.log(infoData);
|
||||
const { data: infoData, error: infoError } = useSWR(formatApiUrl(config, "nginx/proxy-hosts"));
|
||||
|
||||
if (infoError) {
|
||||
return <Widget error="NGINX Proxy Manager API Error" />;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue