62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import ReactDOMServer from "react-dom/server";
|
|
import { StrictMode } from "react";
|
|
import { dangerouslySkipEscape, escapeInject } from "vite-plugin-ssr";
|
|
import theme from "../theme";
|
|
import { ChakraProvider } from "@chakra-ui/react";
|
|
import Fallback from "../components/Fallback";
|
|
import Navigation from "../components/Navigation";
|
|
import Login from "../components/Login";
|
|
import Forbidden from "../components/Forbidden";
|
|
|
|
export const passToClient = ["current_user", "pageProps"];
|
|
|
|
export async function render(
|
|
pageContext: PageContext & { pageProps: { [k: string]: any } }
|
|
) {
|
|
const { exports, Page, pageProps, status } = pageContext;
|
|
|
|
const reactHTML = Page
|
|
? ReactDOMServer.renderToString(
|
|
<StrictMode>
|
|
<ChakraProvider theme={theme}>
|
|
<div className="App">
|
|
<Fallback>
|
|
<Navigation {...pageContext.current_user} />
|
|
{status === 200 ? (
|
|
Page ? (
|
|
<Page {...pageProps} />
|
|
) : (
|
|
""
|
|
)
|
|
) : (
|
|
{ 401: <Login />, 403: <Forbidden /> }[status]
|
|
)}
|
|
</Fallback>
|
|
</div>
|
|
</ChakraProvider>
|
|
</StrictMode>
|
|
)
|
|
: "";
|
|
|
|
return escapeInject`<!DOCTYPE html>
|
|
<html lang="en-US">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="theme-color" content="#00a8f8" />
|
|
<link rel="icon" href="/favicon.ico" />
|
|
<link rel="apple-touch-icon" type="image/png" href="/files/logo192.png" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<meta name="description" content="${
|
|
(exports.description as string) ?? "Car Crushers Website"
|
|
}" />
|
|
<meta property="og:description" content="${
|
|
(exports.description as string | null) ?? "Car Crushers Website"
|
|
}" />
|
|
<title>${(exports.title as string | null) ?? "Car Crushers"}</title>
|
|
</head>
|
|
<body>
|
|
<div id="root">${dangerouslySkipEscape(reactHTML)}</div>
|
|
</body>
|
|
</html>`;
|
|
}
|