mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-07 09:35:54 -08:00
Override config directory with env var.
Until this change, the config directory was assumed to be located at '/config'. This patch retains that default behaviour, but enables users/devs to override that behaviour by setting the HOMEPAGE_CONFIG_DIR variable.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-console */
|
||||
import { join } from "path";
|
||||
import { existsSync, readFileSync, copyFileSync } from "fs";
|
||||
import { copyFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
||||
|
||||
import cache from "memory-cache";
|
||||
import yaml from "js-yaml";
|
||||
@@ -9,8 +9,14 @@ const cacheKey = "homepageEnvironmentVariables";
|
||||
const homepageVarPrefix = "HOMEPAGE_VAR_";
|
||||
const homepageFilePrefix = "HOMEPAGE_FILE_";
|
||||
|
||||
export const CONF_DIR = process.env.HOMEPAGE_CONFIG_DIR ? process.env.HOMEPAGE_CONFIG_DIR : join(process.cwd(), "config");
|
||||
|
||||
export default function checkAndCopyConfig(config) {
|
||||
const configYaml = join(process.cwd(), "config", config);
|
||||
if (!existsSync(CONF_DIR)) {
|
||||
mkdirSync(CONF_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
const configYaml = join(CONF_DIR, config);
|
||||
if (!existsSync(configYaml)) {
|
||||
const configSkeleton = join(process.cwd(), "src", "skeleton", config);
|
||||
try {
|
||||
@@ -62,7 +68,7 @@ export function substituteEnvironmentVars(str) {
|
||||
export function getSettings() {
|
||||
checkAndCopyConfig("settings.yaml");
|
||||
|
||||
const settingsYaml = join(process.cwd(), "config", "settings.yaml");
|
||||
const settingsYaml = join(CONF_DIR, "settings.yaml");
|
||||
const rawFileContents = readFileSync(settingsYaml, "utf8");
|
||||
const fileContents = substituteEnvironmentVars(rawFileContents);
|
||||
const initialSettings = yaml.load(fileContents) ?? {};
|
||||
@@ -79,6 +85,5 @@ export function getSettings() {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return initialSettings
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user