Makes dynamic configuration work in production

If a static file is mounted in the Docker image, it will be read at
each page load and sent to the client.
This commit is contained in:
2023-08-11 11:00:18 +02:00
parent 99b91a7ebb
commit 8660345bf6
7 changed files with 47 additions and 24 deletions

View File

@@ -0,0 +1,20 @@
import { dev } from '$app/environment';
import { config, type Config } from '$lib/config';
import type { PageServerLoad } from './$types';
import { readFileSync } from 'fs';
import * as yml from 'js-yaml';
export const load: PageServerLoad = () => {
if (dev) {
return { config: config };
}
try {
const dynamic = yml.load(readFileSync('/dynamic/config.yml', 'utf8'));
return { config: { ...config, ...dynamic } as Config };
} catch (err) {
console.debug("could not read '/dynamic/config.yml': " + err);
return { config: config };
}
};