♻️ Add env variable validation
This commit is contained in:
@@ -14,9 +14,10 @@ import { AppProps } from 'next/app';
|
||||
import Head from 'next/head';
|
||||
import { useEffect, useState } from 'react';
|
||||
import 'video.js/dist/video-js.css';
|
||||
import { env } from '~/env.js';
|
||||
import { api } from '~/utils/api';
|
||||
|
||||
import nextI18nextConfig from '../../next-i18next.config';
|
||||
import nextI18nextConfig from '../../next-i18next.config.js';
|
||||
import { ChangeAppPositionModal } from '../components/Dashboard/Modals/ChangePosition/ChangeAppPositionModal';
|
||||
import { ChangeWidgetPositionModal } from '../components/Dashboard/Modals/ChangePosition/ChangeWidgetPositionModal';
|
||||
import { EditAppModal } from '../components/Dashboard/Modals/EditAppModal/EditAppModal';
|
||||
@@ -149,26 +150,22 @@ function App(
|
||||
}
|
||||
|
||||
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => {
|
||||
const disableEditMode =
|
||||
process.env.DISABLE_EDIT_MODE && process.env.DISABLE_EDIT_MODE.toLowerCase() === 'true';
|
||||
if (disableEditMode) {
|
||||
if (process.env.DISABLE_EDIT_MODE === 'true') {
|
||||
Consola.warn(
|
||||
'EXPERIMENTAL: You have disabled the edit mode. Modifications are no longer possible and any requests on the API will be dropped. If you want to disable this, unset the DISABLE_EDIT_MODE environment variable. This behaviour may be removed in future versions of Homarr'
|
||||
);
|
||||
}
|
||||
|
||||
if (process.env.DEFAULT_COLOR_SCHEME !== undefined) {
|
||||
Consola.debug(`Overriding the default color scheme with ${process.env.DEFAULT_COLOR_SCHEME}`);
|
||||
if (env.DEFAULT_COLOR_SCHEME !== 'light') {
|
||||
Consola.debug(`Overriding the default color scheme with ${env.DEFAULT_COLOR_SCHEME}`);
|
||||
}
|
||||
|
||||
const colorScheme: ColorScheme = (process.env.DEFAULT_COLOR_SCHEME as ColorScheme) ?? 'light';
|
||||
|
||||
return {
|
||||
pageProps: {
|
||||
colorScheme: getCookie('color-scheme', ctx) || 'light',
|
||||
packageAttributes: getServiceSidePackageAttributes(),
|
||||
editModeEnabled: !disableEditMode,
|
||||
defaultColorScheme: colorScheme,
|
||||
editModeEnabled: process.env.DISABLE_EDIT_MODE !== 'true',
|
||||
defaultColorScheme: env.DEFAULT_COLOR_SCHEME,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Docker from 'dockerode';
|
||||
import { env } from '~/env';
|
||||
|
||||
export default class DockerSingleton extends Docker {
|
||||
private static dockerInstance: DockerSingleton;
|
||||
@@ -10,10 +11,8 @@ export default class DockerSingleton extends Docker {
|
||||
public static getInstance(): DockerSingleton {
|
||||
if (!DockerSingleton.dockerInstance) {
|
||||
DockerSingleton.dockerInstance = new Docker({
|
||||
// If env variable DOCKER_HOST is not set, it will use the default socket
|
||||
...(process.env.DOCKER_HOST && { host: process.env.DOCKER_HOST }),
|
||||
// Same thing for docker port
|
||||
...(process.env.DOCKER_PORT && { port: process.env.DOCKER_PORT }),
|
||||
host: env.DOCKER_HOST,
|
||||
port: env.DOCKER_PORT,
|
||||
});
|
||||
}
|
||||
return DockerSingleton.dockerInstance;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createNextApiHandler } from '@trpc/server/adapters/next';
|
||||
import Consola from 'consola';
|
||||
import { env } from '~/env';
|
||||
import { rootRouter } from '~/server/api/root';
|
||||
import { createTRPCContext } from '~/server/api/trpc';
|
||||
|
||||
@@ -8,7 +9,7 @@ export default createNextApiHandler({
|
||||
router: rootRouter,
|
||||
createContext: createTRPCContext,
|
||||
onError:
|
||||
process.env.NODE_ENV === 'development'
|
||||
env.NODE_ENV === 'development'
|
||||
? ({ path, error }) => {
|
||||
Consola.error(`❌ tRPC failed on ${path ?? '<no-path>'}: ${error.message}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user