From 516423c8bd8bbfe1130ce8a886f36c4d6653d276 Mon Sep 17 00:00:00 2001
From: Simon Grimme <9295182+grimsi@users.noreply.github.com>
Date: Mon, 15 May 2023 02:12:56 +0200
Subject: [PATCH] Implement Caddy widget
---
public/locales/en/common.json | 15 ++++++++-----
src/widgets/caddy/component.jsx | 39 +++++++++++++++++++++++++++++++++
src/widgets/caddy/widget.js | 8 +++++++
src/widgets/components.js | 1 +
src/widgets/widgets.js | 2 ++
5 files changed, 60 insertions(+), 5 deletions(-)
create mode 100644 src/widgets/caddy/component.jsx
create mode 100644 src/widgets/caddy/widget.js
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index 79138cadc..167cbacaf 100755
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -102,6 +102,11 @@
"subscriptions": "Subscriptions",
"unread": "Unread"
},
+ "caddy": {
+ "upstreams": "Upstreams",
+ "requests": "Current requests",
+ "requests_failed": "Failed requests"
+ },
"changedetectionio": {
"totalObserved": "Total Observed",
"diffsDetected": "Diffs Detected"
@@ -517,11 +522,11 @@
"pfsense": {
"load": "Load Avg",
"memory": "Mem Usage",
- "wanStatus": "WAN Status",
- "up": "Up",
- "down": "Down",
- "temp": "Temp",
- "disk": "Disk Usage",
+ "wanStatus": "WAN Status",
+ "up": "Up",
+ "down": "Down",
+ "temp": "Temp",
+ "disk": "Disk Usage",
"wanIP": "WAN IP"
},
"proxmoxbackupserver": {
diff --git a/src/widgets/caddy/component.jsx b/src/widgets/caddy/component.jsx
new file mode 100644
index 000000000..21320cd67
--- /dev/null
+++ b/src/widgets/caddy/component.jsx
@@ -0,0 +1,39 @@
+import { useTranslation } from "next-i18next";
+
+import Container from "components/services/widget/container";
+import Block from "components/services/widget/block";
+import useWidgetAPI from "utils/proxy/use-widget-api";
+
+export default function Component({ service }) {
+ const { t } = useTranslation();
+
+ const { widget } = service;
+ const { data: resultData, error: resultError } = useWidgetAPI(widget, "result");
+
+
+ if (resultError) {
+ return ;
+ }
+
+ if (!resultData) {
+ return (
+ ,
+
+
+
+
+ );
+ }
+
+ const upstreams = resultData.length;
+ const requests = resultData.reduce((acc, val) => acc + val.num_requests, 0);
+ const requestsFailed = resultData.reduce((acc, val) => acc + val.fails, 0);
+
+ return (
+
+
+
+
+
+ );
+}
diff --git a/src/widgets/caddy/widget.js b/src/widgets/caddy/widget.js
new file mode 100644
index 000000000..2fb1978bc
--- /dev/null
+++ b/src/widgets/caddy/widget.js
@@ -0,0 +1,8 @@
+import genericProxyHandler from "utils/proxy/handlers/generic";
+
+const widget = {
+ api: "{url}/reverse_proxy/upstreams",
+ proxyHandler: genericProxyHandler,
+};
+
+export default widget;
diff --git a/src/widgets/components.js b/src/widgets/components.js
index 754898bfe..8181321d0 100644
--- a/src/widgets/components.js
+++ b/src/widgets/components.js
@@ -6,6 +6,7 @@ const components = {
authentik: dynamic(() => import("./authentik/component")),
autobrr: dynamic(() => import("./autobrr/component")),
bazarr: dynamic(() => import("./bazarr/component")),
+ caddy: dynamic(() => import("./caddy/component")),
changedetectionio: dynamic(() => import("./changedetectionio/component")),
channelsdvrserver: dynamic(() => import("./channelsdvrserver/component")),
cloudflared: dynamic(() => import("./cloudflared/component")),
diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js
index f7b07a96e..cf0868f53 100644
--- a/src/widgets/widgets.js
+++ b/src/widgets/widgets.js
@@ -3,6 +3,7 @@ import audiobookshelf from "./audiobookshelf/widget";
import authentik from "./authentik/widget";
import autobrr from "./autobrr/widget";
import bazarr from "./bazarr/widget";
+import caddy from "./caddy/widget";
import changedetectionio from "./changedetectionio/widget";
import channelsdvrserver from "./channelsdvrserver/widget";
import cloudflared from "./cloudflared/widget";
@@ -87,6 +88,7 @@ const widgets = {
authentik,
autobrr,
bazarr,
+ caddy,
changedetectionio,
channelsdvrserver,
cloudflared,