Only server-side render non-auth systems

pull/674/head
Zef Hemel 2024-01-28 19:24:59 +01:00
parent e2aa869660
commit dbabba7326
1 changed files with 14 additions and 11 deletions

View File

@ -113,20 +113,23 @@ export class HttpServer {
// Replaces some template variables in index.html in a rather ad-hoc manner, but YOLO // Replaces some template variables in index.html in a rather ad-hoc manner, but YOLO
async renderHtmlPage(spaceServer: SpaceServer, pageName: string) { async renderHtmlPage(spaceServer: SpaceServer, pageName: string) {
console.log("Server side rendering", pageName);
let html = ""; let html = "";
try { if (!spaceServer.auth) {
const { data } = await spaceServer.spacePrimitives.readFile( // Only attempt server-side rendering when this site is not protected by auth
`${pageName}.md`, try {
); const { data } = await spaceServer.spacePrimitives.readFile(
const text = new TextDecoder().decode(data); `${pageName}.md`,
const tree = parse(extendedMarkdownLanguage, text); );
html = renderMarkdownToHtml(tree); const text = new TextDecoder().decode(data);
} catch (e: any) { const tree = parse(extendedMarkdownLanguage, text);
if (e.message !== "Not found") { html = renderMarkdownToHtml(tree);
console.error("Error server-side rendering page", e); } catch (e: any) {
if (e.message !== "Not found") {
console.error("Error server-side rendering page", e);
}
} }
} }
// TODO: Replace this with a proper template engine
return this.clientAssetBundle.readTextFileSync(".client/index.html") return this.clientAssetBundle.readTextFileSync(".client/index.html")
.replace( .replace(
"{{SPACE_PATH}}", "{{SPACE_PATH}}",