import { baseUrl } from "./baseUrl"; import useSWR, { SWRConfig } from "swr"; import { WsProvider } from "./ws"; import axios from "axios"; import { ReactNode } from "react"; axios.defaults.baseURL = `${baseUrl}api/`; type ApiProviderType = { children?: ReactNode; options?: Record; }; export function ApiProvider({ children, options }: ApiProviderType) { axios.defaults.headers.common = { "X-CSRF-TOKEN": 1, "X-CACHE-BYPASS": 1, }; return ( axios.get(path, { params }).then((res) => res.data), ...options, }} > {children} ); } type WsWithConfigType = { children: ReactNode; }; type FrigateConfig = Record; function WsWithConfig({ children }: WsWithConfigType) { const { data } = useSWR("config"); return data ? {children} : children; } export function useApiHost() { return baseUrl; }