forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tsx
More file actions
48 lines (43 loc) · 1.34 KB
/
main.tsx
File metadata and controls
48 lines (43 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import React from "react"
import ReactDOM from "react-dom/client"
import { BrowserRouter } from "react-router-dom"
import App from "./App"
import { ErrorBoundary } from "./components/ErrorBoundary"
import "./index.css"
// Fail loudly if the SPA is being served from somewhere unexpected — the
// router and API client both assume we live at /admin.
if (
typeof globalThis.window !== "undefined"
&& !globalThis.location.pathname.startsWith("/admin")
) {
console.warn(
"Copilot API admin SPA loaded from",
globalThis.location.pathname,
"— expected /admin/*. Routing may misbehave.",
)
}
const queryClient = new QueryClient({
defaultOptions: {
queries: {
// Admin pages are operator-facing; we'd rather refetch on focus than
// show stale numbers. Networks here are localhost so cost is trivial.
refetchOnWindowFocus: true,
retry: 1,
staleTime: 10_000,
},
},
})
const root = document.querySelector("#root")
if (!root) throw new Error("#root missing")
ReactDOM.createRoot(root).render(
<React.StrictMode>
<ErrorBoundary>
<QueryClientProvider client={queryClient}>
<BrowserRouter basename="/admin">
<App />
</BrowserRouter>
</QueryClientProvider>
</ErrorBoundary>
</React.StrictMode>,
)