mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-12 08:25:47 +01:00
Fix usage of default config
This commit is contained in:
@@ -5,9 +5,11 @@ import { LoadConfigComponent } from '../components/Config/LoadConfig';
|
|||||||
import { Dashboard } from '../components/Dashboard/Dashboard';
|
import { Dashboard } from '../components/Dashboard/Dashboard';
|
||||||
import Layout from '../components/layout/Layout';
|
import Layout from '../components/layout/Layout';
|
||||||
import { useInitConfig } from '../config/init';
|
import { useInitConfig } from '../config/init';
|
||||||
|
import { getFallbackConfig } from '../tools/config/getFallbackConfig';
|
||||||
import { getFrontendConfig } from '../tools/config/getFrontendConfig';
|
import { getFrontendConfig } from '../tools/config/getFrontendConfig';
|
||||||
import { getServerSideTranslations } from '../tools/getServerSideTranslations';
|
import { getServerSideTranslations } from '../tools/getServerSideTranslations';
|
||||||
import { dashboardNamespaces } from '../tools/translation-namespaces';
|
import { dashboardNamespaces } from '../tools/translation-namespaces';
|
||||||
|
import { ConfigType } from '../types/config';
|
||||||
import { DashboardServerSideProps } from '../types/dashboardPageType';
|
import { DashboardServerSideProps } from '../types/dashboardPageType';
|
||||||
|
|
||||||
export async function getServerSideProps({
|
export async function getServerSideProps({
|
||||||
@@ -28,38 +30,7 @@ export async function getServerSideProps({
|
|||||||
res.end();
|
res.end();
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
config: {
|
config: getFallbackConfig() as unknown as ConfigType,
|
||||||
schemaVersion: 1,
|
|
||||||
configProperties: {
|
|
||||||
name: 'Default Configuration',
|
|
||||||
},
|
|
||||||
apps: [],
|
|
||||||
settings: {
|
|
||||||
common: {
|
|
||||||
searchEngine: {
|
|
||||||
type: 'google',
|
|
||||||
properties: {
|
|
||||||
enabled: true,
|
|
||||||
openInNewTab: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defaultConfig: 'default',
|
|
||||||
},
|
|
||||||
customization: {
|
|
||||||
layout: {
|
|
||||||
enabledLeftSidebar: false,
|
|
||||||
enabledRightSidebar: false,
|
|
||||||
enabledSearchbar: true,
|
|
||||||
enabledDocker: false,
|
|
||||||
enabledPing: false,
|
|
||||||
},
|
|
||||||
colors: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
categories: [],
|
|
||||||
wrappers: [],
|
|
||||||
widgets: [],
|
|
||||||
},
|
|
||||||
configName,
|
configName,
|
||||||
...translations,
|
...translations,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import Consola from 'consola';
|
import Consola from 'consola';
|
||||||
import { BackendConfigType } from '../../types/config';
|
import { BackendConfigType, ConfigType } from '../../types/config';
|
||||||
import { backendMigrateConfig } from './backendMigrateConfig';
|
import { backendMigrateConfig } from './backendMigrateConfig';
|
||||||
import { configExists } from './configExists';
|
import { configExists } from './configExists';
|
||||||
import { getFallbackConfig } from './getFallbackConfig';
|
import { getFallbackConfig } from './getFallbackConfig';
|
||||||
import { readConfig } from './readConfig';
|
import { readConfig } from './readConfig';
|
||||||
|
|
||||||
export const getConfig = (name: string): BackendConfigType => {
|
export const getConfig = (name: string): BackendConfigType => {
|
||||||
if (!configExists(name)) return getFallbackConfig();
|
if (!configExists(name)) return getFallbackConfig() as unknown as ConfigType;
|
||||||
// Else if config exists but contains no "schema_version" property
|
// Else if config exists but contains no "schema_version" property
|
||||||
// then it is an old config file and we should try to migrate it
|
// then it is an old config file and we should try to migrate it
|
||||||
// to the new format.
|
// to the new format.
|
||||||
|
|||||||
@@ -1,39 +1,8 @@
|
|||||||
import { BackendConfigType } from '../../types/config';
|
import defaultConfig from '../../../data/configs/default.json';
|
||||||
|
|
||||||
export const getFallbackConfig = (name?: string): BackendConfigType => ({
|
export const getFallbackConfig = (name?: string) => ({
|
||||||
schemaVersion: 1,
|
...defaultConfig,
|
||||||
configProperties: {
|
configProperties: {
|
||||||
name: name ?? 'default',
|
name: name ?? 'default',
|
||||||
},
|
},
|
||||||
categories: [],
|
|
||||||
widgets: [],
|
|
||||||
apps: [],
|
|
||||||
settings: {
|
|
||||||
common: {
|
|
||||||
searchEngine: {
|
|
||||||
type: 'google',
|
|
||||||
properties: {
|
|
||||||
enabled: true,
|
|
||||||
openInNewTab: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defaultConfig: 'default',
|
|
||||||
},
|
|
||||||
customization: {
|
|
||||||
colors: {},
|
|
||||||
layout: {
|
|
||||||
enabledDocker: false,
|
|
||||||
enabledLeftSidebar: false,
|
|
||||||
enabledPing: false,
|
|
||||||
enabledRightSidebar: false,
|
|
||||||
enabledSearchbar: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wrappers: [
|
|
||||||
{
|
|
||||||
id: 'default',
|
|
||||||
position: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,29 +1,14 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { getFallbackConfig } from './config/getFallbackConfig';
|
||||||
|
import { ConfigType } from '../types/config';
|
||||||
|
|
||||||
export function getConfig(name: string, props: any = undefined) {
|
export function getConfig(name: string, props: any = undefined) {
|
||||||
// Check if the config file exists
|
// Check if the config file exists
|
||||||
const configPath = path.join(process.cwd(), 'data/configs', `${name}.json`);
|
const configPath = path.join(process.cwd(), 'data/configs', `${name}.json`);
|
||||||
if (!fs.existsSync(configPath)) {
|
if (!fs.existsSync(configPath)) {
|
||||||
return {
|
return getFallbackConfig() as unknown as ConfigType;
|
||||||
props: {
|
|
||||||
configName: name,
|
|
||||||
config: {
|
|
||||||
name: name.toString(),
|
|
||||||
services: [],
|
|
||||||
settings: {
|
|
||||||
searchUrl: 'https://www.google.com/search?q=',
|
|
||||||
},
|
|
||||||
modules: {
|
|
||||||
'Search Bar': {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = fs.readFileSync(configPath, 'utf8');
|
const config = fs.readFileSync(configPath, 'utf8');
|
||||||
// Print loaded config
|
// Print loaded config
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user