mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 08:20:58 +00:00 
			
		
		
		
	Enforce method
This commit is contained in:
		
							parent
							
								
									67a9f4983c
								
							
						
					
					
						commit
						19c3ac0d7e
					
				@ -41,6 +41,11 @@ export default async function handler(req, res) {
 | 
				
			|||||||
        const endpoint = mapping?.endpoint;
 | 
					        const endpoint = mapping?.endpoint;
 | 
				
			||||||
        const endpointProxy = mapping?.proxyHandler || serviceProxyHandler;
 | 
					        const endpointProxy = mapping?.proxyHandler || serviceProxyHandler;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (mapping.method && mapping.method !== req.method) {
 | 
				
			||||||
 | 
					          logger.debug("Unsupported method: %s", req.method);
 | 
				
			||||||
 | 
					          return res.status(403).json({ error: "Unsupported method" });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!endpoint) {
 | 
					        if (!endpoint) {
 | 
				
			||||||
          logger.debug("Unsupported service endpoint: %s", type);
 | 
					          logger.debug("Unsupported service endpoint: %s", type);
 | 
				
			||||||
          return res.status(403).json({ error: "Unsupported service endpoint" });
 | 
					          return res.status(403).json({ error: "Unsupported service endpoint" });
 | 
				
			||||||
 | 
				
			|||||||
@ -225,7 +225,9 @@ export default function Component({ service }) {
 | 
				
			|||||||
      }),
 | 
					      }),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    const url = `/api/services/proxy?${params.toString()}`;
 | 
					    const url = `/api/services/proxy?${params.toString()}`;
 | 
				
			||||||
    await fetch(url).then(() => {
 | 
					    await fetch(url, {
 | 
				
			||||||
 | 
					      method: "POST",
 | 
				
			||||||
 | 
					    }).then(() => {
 | 
				
			||||||
      sessionMutate();
 | 
					      sessionMutate();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,18 +1,26 @@
 | 
				
			|||||||
import { useTranslation } from "next-i18next";
 | 
					import { useTranslation } from "next-i18next";
 | 
				
			||||||
 | 
					import { useEffect, useState } from "react";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Container from "components/services/widget/container";
 | 
					import Container from "components/services/widget/container";
 | 
				
			||||||
import Block from "components/services/widget/block";
 | 
					import Block from "components/services/widget/block";
 | 
				
			||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
					import { formatProxyUrl } from "utils/proxy/api-helpers";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Component({ service }) {
 | 
					export default function Component({ service }) {
 | 
				
			||||||
  const { t } = useTranslation();
 | 
					  const { t } = useTranslation();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { widget } = service;
 | 
					  const { widget } = service;
 | 
				
			||||||
  const { data: stats, error: stashError } = useWidgetAPI(widget, "stats");
 | 
					  const [stats, setStats] = useState(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (stashError) {
 | 
					  useEffect(() => {
 | 
				
			||||||
    return <Container service={service} error={stashError} />;
 | 
					    async function fetchStats() {
 | 
				
			||||||
 | 
					      const url = formatProxyUrl(widget, "stats");
 | 
				
			||||||
 | 
					      const res = await fetch(url, { method: "POST" });
 | 
				
			||||||
 | 
					      setStats(await res.json());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (!stats) {
 | 
				
			||||||
 | 
					      fetchStats();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }, [widget, stats]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!stats) {
 | 
					  if (!stats) {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
 | 
				
			|||||||
@ -1,16 +1,30 @@
 | 
				
			|||||||
 | 
					import { useEffect, useState } from "react";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Container from "components/services/widget/container";
 | 
					import Container from "components/services/widget/container";
 | 
				
			||||||
import Block from "components/services/widget/block";
 | 
					import Block from "components/services/widget/block";
 | 
				
			||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
					import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
				
			||||||
 | 
					import { formatProxyUrl } from "utils/proxy/api-helpers";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Component({ service }) {
 | 
					export default function Component({ service }) {
 | 
				
			||||||
  const { widget } = service;
 | 
					  const { widget } = service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { data: workersData, error: workersError } = useWidgetAPI(widget, "workers");
 | 
					  const { data: workersData, error: workersError } = useWidgetAPI(widget, "workers");
 | 
				
			||||||
  const { data: pendingData, error: pendingError } = useWidgetAPI(widget, "pending");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (workersError || pendingError) {
 | 
					  const [pendingData, setPendingData] = useState(null);
 | 
				
			||||||
    const finalError = workersError ?? pendingError;
 | 
					
 | 
				
			||||||
    return <Container service={service} error={finalError} />;
 | 
					  useEffect(() => {
 | 
				
			||||||
 | 
					    async function fetchPending() {
 | 
				
			||||||
 | 
					      const url = formatProxyUrl(widget, "pending");
 | 
				
			||||||
 | 
					      const res = await fetch(url, { method: "POST" });
 | 
				
			||||||
 | 
					      setPendingData(await res.json());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (!pendingData) {
 | 
				
			||||||
 | 
					      fetchPending();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }, [widget, pendingData]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (workersError) {
 | 
				
			||||||
 | 
					    return <Container service={service} error={workersError} />;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!workersData || !pendingData) {
 | 
					  if (!workersData || !pendingData) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,18 +1,26 @@
 | 
				
			|||||||
import { useTranslation } from "next-i18next";
 | 
					import { useTranslation } from "next-i18next";
 | 
				
			||||||
 | 
					import { useEffect, useState } from "react";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Container from "components/services/widget/container";
 | 
					import Container from "components/services/widget/container";
 | 
				
			||||||
import Block from "components/services/widget/block";
 | 
					import Block from "components/services/widget/block";
 | 
				
			||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
					import { formatProxyUrl } from "utils/proxy/api-helpers";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Component({ service }) {
 | 
					export default function Component({ service }) {
 | 
				
			||||||
  const { widget } = service;
 | 
					  const { widget } = service;
 | 
				
			||||||
  const { t } = useTranslation();
 | 
					  const { t } = useTranslation();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { data: uptimerobotData, error: uptimerobotError } = useWidgetAPI(widget, "getmonitors");
 | 
					  const [uptimerobotData, setUptimerobotData] = useState(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (uptimerobotError) {
 | 
					  useEffect(() => {
 | 
				
			||||||
    return <Container service={service} error={uptimerobotError} />;
 | 
					    async function fetchData() {
 | 
				
			||||||
 | 
					      const url = formatProxyUrl(widget, "getmonitors");
 | 
				
			||||||
 | 
					      const res = await fetch(url, { method: "POST" });
 | 
				
			||||||
 | 
					      setUptimerobotData(await res.json());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (!uptimerobotData) {
 | 
				
			||||||
 | 
					      fetchData();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }, [widget, uptimerobotData]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!uptimerobotData) {
 | 
					  if (!uptimerobotData) {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user