mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-09-23 17:52:05 +02:00
* implement nginx caching * bypass cache from frigate frontend, reduce to 5s * set cache time to 2s * cache 200s for 5s * exclude vod endpoints from cache
34 lines
789 B
JavaScript
34 lines
789 B
JavaScript
import { h } from 'preact';
|
|
import { baseUrl } from './baseUrl';
|
|
import useSWR, { SWRConfig } from 'swr';
|
|
import { WsProvider } from './ws';
|
|
import axios from 'axios';
|
|
|
|
axios.defaults.baseURL = `${baseUrl}api/`;
|
|
axios.defaults.headers.common = {
|
|
'X-CSRF-TOKEN': 1,
|
|
'X-CACHE-BYPASS': 1,
|
|
};
|
|
|
|
export function ApiProvider({ children, options }) {
|
|
return (
|
|
<SWRConfig
|
|
value={{
|
|
fetcher: (path, params) => axios.get(path, { params }).then((res) => res.data),
|
|
...options,
|
|
}}
|
|
>
|
|
<WsWithConfig>{children}</WsWithConfig>
|
|
</SWRConfig>
|
|
);
|
|
}
|
|
|
|
function WsWithConfig({ children }) {
|
|
const { data } = useSWR('config');
|
|
return data ? <WsProvider config={data}>{children}</WsProvider> : children;
|
|
}
|
|
|
|
export function useApiHost() {
|
|
return baseUrl;
|
|
}
|