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:
7
package-lock.json
generated
7
package-lock.json
generated
@@ -8,7 +8,8 @@
|
||||
"name": "flanders",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.3.1"
|
||||
"dotenv": "^16.3.1",
|
||||
"js-yaml": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@modyfi/vite-plugin-yaml": "^1.0.4",
|
||||
@@ -1322,8 +1323,7 @@
|
||||
"node_modules/argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
||||
"dev": true
|
||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
|
||||
},
|
||||
"node_modules/aria-query": {
|
||||
"version": "5.3.0",
|
||||
@@ -2443,7 +2443,6 @@
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
},
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.3.1"
|
||||
"dotenv": "^16.3.1",
|
||||
"js-yaml": "^4.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
title: 'Hello World !!'
|
||||
subtitle: 'I am a new pilot.'
|
||||
|
||||
services:
|
||||
- title: '/Cloud'
|
||||
subtitle: 'Private Cloud Utilities'
|
||||
icon: 'fas fa-cloud'
|
||||
items:
|
||||
- title: 'NAS'
|
||||
subtitle: 'Network Attached Storage'
|
||||
icon: 'fas fa-hard-drive'
|
||||
target: '_blank'
|
||||
url: '/NAS'
|
||||
keywords: 'cloud storage files'
|
||||
1
src/config.yml
Symbolic link
1
src/config.yml
Symbolic link
@@ -0,0 +1 @@
|
||||
../static/config.yml
|
||||
@@ -1,4 +1,4 @@
|
||||
import configData from './config.yml';
|
||||
import configData from '../config.yml';
|
||||
|
||||
export type Brand = {
|
||||
logo?: string;
|
||||
20
src/routes/+page.server.ts
Normal file
20
src/routes/+page.server.ts
Normal 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 };
|
||||
}
|
||||
};
|
||||
@@ -1,8 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { config } from '../config';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<h1>{config.title}</h1>
|
||||
{#if config.subtitle}
|
||||
<h2>{config.subtitle}</h2>
|
||||
<h1>{data.config.title}</h1>
|
||||
{#if data.config.subtitle}
|
||||
<h2>{data.config.subtitle}</h2>
|
||||
{/if}
|
||||
|
||||
14
static/config.yml
Normal file
14
static/config.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
title: 'Hello World !!'
|
||||
subtitle: 'actually, I am a new pilot.'
|
||||
|
||||
services:
|
||||
- title: '/Cloud'
|
||||
subtitle: 'Private Cloud Utilities'
|
||||
icon: 'fas fa-cloud'
|
||||
items:
|
||||
- title: 'NAS'
|
||||
subtitle: 'Network Attached Storage'
|
||||
icon: 'fas fa-hard-drive'
|
||||
target: '_blank'
|
||||
url: '/NAS'
|
||||
keywords: 'cloud storage files'
|
||||
Reference in New Issue
Block a user