send config to client in base64 string

This commit is contained in:
Hri7566 2024-10-23 02:32:19 -04:00
parent 021c349881
commit ccac29039c
1 changed files with 17 additions and 10 deletions

View File

@ -9,7 +9,7 @@ import { getMOTD } from "../util/motd";
import nunjucks from "nunjucks"; import nunjucks from "nunjucks";
import type { Server, ServerWebSocket } from "bun"; import type { Server, ServerWebSocket } from "bun";
import { ConfigManager } from "~/util/config"; import { ConfigManager } from "~/util/config";
import { config as usersConfig } from "./usersConfig"; import { config as usersConfig, usersConfigPath } from "./usersConfig";
const logger = new Logger("WebSocket Server"); const logger = new Logger("WebSocket Server");
@ -23,14 +23,13 @@ interface IFrontendConfig {
winter: boolean; winter: boolean;
} }
const config = ConfigManager.loadConfig<IFrontendConfig>( const configPath = "config/frontend.yml";
"config/frontend.yml",
{ const config = ConfigManager.loadConfig<IFrontendConfig>(configPath, {
topButtons: "original", topButtons: "original",
disableChat: false, disableChat: false,
winter: false winter: false
} });
);
/** /**
* Get a rendered version of the index file * Get a rendered version of the index file
@ -45,10 +44,18 @@ async function getIndex() {
const index = Bun.file("./public/index.html"); const index = Bun.file("./public/index.html");
const base64config = btoa(
JSON.stringify({
config: ConfigManager.getOriginalConfigObject(configPath),
usersConfig: ConfigManager.getOriginalConfigObject(usersConfigPath)
})
);
const rendered = nunjucks.renderString(await index.text(), { const rendered = nunjucks.renderString(await index.text(), {
motd: getMOTD(), motd: getMOTD(),
config, config,
usersConfig usersConfig,
base64config
}); });
const response = new Response(rendered); const response = new Response(rendered);