25 lines
677 B
TypeScript
25 lines
677 B
TypeScript
import { dev } from "$app/environment";
|
|
import { clientConfig, stripPrivateFields, type Config } from "$lib/config";
|
|
import type { Handle } from "@sveltejs/kit";
|
|
import { readFile } from 'fs';
|
|
import * as yml from 'js-yaml';
|
|
|
|
async function reloadConfig(): Promise<Config> {
|
|
try {
|
|
const dynamic = yml.load(await readFile('/dynamic/config.yml', 'utf8'));
|
|
return stripPrivateFields({ ...clientConfig, ...dynamic });
|
|
} catch (err) {
|
|
return clientConfig;
|
|
}
|
|
|
|
}
|
|
|
|
export const handle: Handle = async ({ event, resolve }) => {
|
|
if ( dev == false ) {
|
|
Object.assign(event.locals,{config: await reloadConfig()});
|
|
}
|
|
|
|
const response = await resolve(event);
|
|
return response;
|
|
}
|