Router.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { lazy, Suspense } from "react";
  2. import { BrowserRouter, Route, Routes } from "react-router-dom";
  3. import {
  4. ErrorNotFound,
  5. LoadingPage,
  6. Page,
  7. SiteContainer,
  8. SiteFooter,
  9. SiteHeader,
  10. SiteMenu,
  11. Unhealthy,
  12. } from "src/components";
  13. import { useAuthState } from "src/context";
  14. import { useHealth } from "src/hooks";
  15. const Setup = lazy(() => import("src/pages/Setup"));
  16. const Login = lazy(() => import("src/pages/Login"));
  17. const Dashboard = lazy(() => import("src/pages/Dashboard"));
  18. const Settings = lazy(() => import("src/pages/Settings"));
  19. const Certificates = lazy(() => import("src/pages/Certificates"));
  20. const Access = lazy(() => import("src/pages/Access"));
  21. const AuditLog = lazy(() => import("src/pages/AuditLog"));
  22. const Users = lazy(() => import("src/pages/Users"));
  23. const ProxyHosts = lazy(() => import("src/pages/Nginx/ProxyHosts"));
  24. const RedirectionHosts = lazy(() => import("src/pages/Nginx/RedirectionHosts"));
  25. const DeadHosts = lazy(() => import("src/pages/Nginx/DeadHosts"));
  26. const Streams = lazy(() => import("src/pages/Nginx/Streams"));
  27. function Router() {
  28. const health = useHealth();
  29. const { authenticated } = useAuthState();
  30. if (health.isLoading) {
  31. return <LoadingPage />;
  32. }
  33. if (health.isError || health.data?.status !== "OK") {
  34. return <Unhealthy />;
  35. }
  36. if (!health.data?.setup) {
  37. return <Setup />;
  38. }
  39. if (!authenticated) {
  40. return (
  41. <Suspense fallback={<LoadingPage />}>
  42. <Login />
  43. </Suspense>
  44. );
  45. }
  46. return (
  47. <BrowserRouter>
  48. <Page>
  49. <div>
  50. <SiteHeader />
  51. <SiteMenu />
  52. </div>
  53. <SiteContainer>
  54. <Suspense fallback={<LoadingPage noLogo />}>
  55. <Routes>
  56. <Route path="*" element={<ErrorNotFound />} />
  57. <Route path="/certificates" element={<Certificates />} />
  58. <Route path="/access" element={<Access />} />
  59. <Route path="/audit-log" element={<AuditLog />} />
  60. <Route path="/settings" element={<Settings />} />
  61. <Route path="/users" element={<Users />} />
  62. <Route path="/nginx/proxy" element={<ProxyHosts />} />
  63. <Route path="/nginx/redirection" element={<RedirectionHosts />} />
  64. <Route path="/nginx/404" element={<DeadHosts />} />
  65. <Route path="/nginx/stream" element={<Streams />} />
  66. <Route path="/" element={<Dashboard />} />
  67. </Routes>
  68. </Suspense>
  69. </SiteContainer>
  70. <SiteFooter />
  71. </Page>
  72. </BrowserRouter>
  73. );
  74. }
  75. export default Router;