headplane/app/root.tsx

74 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-03-25 17:51:11 -04:00
import type { LinksFunction, MetaFunction } from '@remix-run/node'
import {
2024-03-25 17:51:11 -04:00
Links,
Meta,
Outlet,
Scripts,
2024-03-29 16:14:35 -04:00
ScrollRestoration
2024-03-25 17:51:11 -04:00
} from '@remix-run/react'
2024-03-29 16:14:35 -04:00
import { ErrorPopup } from '~/components/Error'
2024-03-25 18:47:15 -04:00
import Toaster from '~/components/Toaster'
2024-03-25 17:51:11 -04:00
import stylesheet from '~/tailwind.css?url'
import { getContext, registerConfigWatcher } from '~/utils/config'
2024-03-25 17:51:11 -04:00
export const meta: MetaFunction = () => [
{ title: 'Headplane' },
{ name: 'description', content: 'A frontend for the headscale coordination server' }
]
export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: stylesheet }
]
2024-03-28 17:03:37 -04:00
export async function loader() {
const context = await getContext()
registerConfigWatcher()
2024-03-28 17:03:37 -04:00
if (context.headscaleUrl.length === 0) {
throw new Error('No headscale URL was provided either by the HEADSCALE_URL environment variable or the config file')
2024-03-25 17:51:11 -04:00
}
if (!process.env.COOKIE_SECRET) {
throw new Error('The COOKIE_SECRET environment variable is required')
}
if (!process.env.API_KEY) {
throw new Error('The API_KEY environment variable is required')
}
2024-03-29 01:53:32 -04:00
if (!process.env.HEADSCALE_CONTAINER) {
throw new Error('The HEADSCALE_CONTAINER environment variable is required')
}
2024-03-25 17:51:11 -04:00
// eslint-disable-next-line unicorn/no-null
return null
}
export function Layout({ children }: { readonly children: React.ReactNode }) {
return (
<html lang='en'>
<head>
<meta charSet='utf-8'/>
<meta name='viewport' content='width=device-width, initial-scale=1'/>
<Meta/>
<Links/>
</head>
<body className='overscroll-none dark:bg-zinc-900 dark:text-white'>
2024-03-25 17:51:11 -04:00
{children}
2024-03-25 18:47:15 -04:00
<Toaster/>
2024-03-25 17:51:11 -04:00
<ScrollRestoration/>
<Scripts/>
</body>
</html>
)
}
export function ErrorBoundary() {
2024-03-29 16:14:35 -04:00
return <ErrorPopup/>
}
export default function App() {
2024-03-25 17:51:11 -04:00
return <Outlet/>
}