From 2e1766e04056e6038cad432b673ce072911b9fd2 Mon Sep 17 00:00:00 2001 From: nite-knite Date: Thu, 9 May 2024 18:00:21 +0800 Subject: [PATCH] feat: update env validation --- web/.env.example | 16 ++++---- web/README.md | 19 +++++---- .../header/account-dropdown/index.tsx | 4 +- .../components/header/github-star/index.tsx | 2 +- web/app/layout.tsx | 9 +---- web/app/signin/normalForm.tsx | 9 ++--- web/context/app-context.tsx | 4 +- web/docker/entrypoint.sh | 2 +- web/env.ts | 17 ++++---- web/package.json | 5 ++- web/scripts/update-env.mjs | 37 ------------------ web/tsconfig.json | 3 +- web/yarn.lock | 39 ++++++++++++++++--- 13 files changed, 77 insertions(+), 89 deletions(-) delete mode 100644 web/scripts/update-env.mjs diff --git a/web/.env.example b/web/.env.example index 6a0e641e9b..1228ece1fd 100644 --- a/web/.env.example +++ b/web/.env.example @@ -4,15 +4,15 @@ NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT NEXT_PUBLIC_EDITION=SELF_HOSTED # The base URL of console application, refers to the Console base URL of WEB service if console domain is # different from api or web app domain. -# example: http://cloud.dify.ai/console/api -NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api +# example: http://cloud.dify.ai/console/api or http://localhost:5001/console/api +NEXT_PUBLIC_API_PREFIX= # The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from # console or api domain. -# example: http://udify.app/api -NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api - -# SENTRY +# example: http://udify.app/api or http://localhost:5001/api +NEXT_PUBLIC_PUBLIC_API_PREFIX= +# Sentry NEXT_PUBLIC_SENTRY_DSN= - -NEXT_PUBLIC_SITE_ABOUT= +# Pass 'TRUE' to show maintenance notice NEXT_PUBLIC_MAINTENANCE_NOTICE= +# Pass 'TRUE' to hide cloud service release info and running status +NEXT_PUBLIC_HIDE_ABOUT_INFO= diff --git a/web/README.md b/web/README.md index 13301599c1..35219be593 100644 --- a/web/README.md +++ b/web/README.md @@ -22,19 +22,18 @@ NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT NEXT_PUBLIC_EDITION=SELF_HOSTED # The base URL of console application, refers to the Console base URL of WEB service if console domain is # different from api or web app domain. -# example: http://cloud.dify.ai/console/api -NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api +# example: http://cloud.dify.ai/console/api or http://localhost:5001/console/api +NEXT_PUBLIC_API_PREFIX= # The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from # console or api domain. -# example: http://udify.app/api -NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api - -# SENTRY +# example: http://udify.app/api or http://localhost:5001/api +NEXT_PUBLIC_PUBLIC_API_PREFIX= +# Sentry NEXT_PUBLIC_SENTRY_DSN= - - - - +# Pass 'TRUE' to show maintenance notice +NEXT_PUBLIC_MAINTENANCE_NOTICE= +# Pass 'TRUE' to hide release info and service status +NEXT_PUBLIC_HIDE_ABOUT_INFO= ``` Finally, run the development server: diff --git a/web/app/components/header/account-dropdown/index.tsx b/web/app/components/header/account-dropdown/index.tsx index ba9f9f32c6..36409ab09f 100644 --- a/web/app/components/header/account-dropdown/index.tsx +++ b/web/app/components/header/account-dropdown/index.tsx @@ -17,6 +17,8 @@ import { ArrowUpRight, ChevronDown } from '@/app/components/base/icons/src/vende import { LogOut01 } from '@/app/components/base/icons/src/vender/line/general' import { useModalContext } from '@/context/modal-context' import { LanguagesSupported } from '@/i18n/language' +import { env } from '@/env' + export type IAppSelecotr = { isMobile: boolean } @@ -134,7 +136,7 @@ export default function AppSelector({ isMobile }: IAppSelecotr) { { - document?.body?.getAttribute('data-public-site-about') !== 'hide' && ( + env.NEXT_PUBLIC_HIDE_ABOUT_INFO !== 'TRUE' && (
setAboutVisible(true)}>
{t('common.userProfile.about')}
diff --git a/web/app/components/header/github-star/index.tsx b/web/app/components/header/github-star/index.tsx index 9d74145ec7..0c9e39db0a 100644 --- a/web/app/components/header/github-star/index.tsx +++ b/web/app/components/header/github-star/index.tsx @@ -19,7 +19,7 @@ const GithubStar = () => { useEffect(() => { (async () => { try { - if (env.NODE_ENV === 'development') + if (env.NODE_ENV?.toUpperCase() === 'DEVELOPMENT') return setGithubRepo(await getStar()) diff --git a/web/app/layout.tsx b/web/app/layout.tsx index 599bb778b1..529fa8db27 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -6,7 +6,6 @@ import Topbar from './components/base/topbar' import { getLocaleOnServer } from '@/i18n/server' import './styles/globals.css' import './styles/markdown.scss' -import { env } from '@/env' export const metadata = { title: 'Dify', @@ -35,12 +34,8 @@ const LocaleLayout = ({ - - + + {/* @ts-expect-error Async Server Component */} diff --git a/web/app/signin/normalForm.tsx b/web/app/signin/normalForm.tsx index bb213c25ff..d0bb17d55f 100644 --- a/web/app/signin/normalForm.tsx +++ b/web/app/signin/normalForm.tsx @@ -5,13 +5,11 @@ import { useRouter } from 'next/navigation' import classNames from 'classnames' import useSWR from 'swr' import Link from 'next/link' -import { useContext } from 'use-context-selector' import Toast from '../components/base/toast' import style from './page.module.css' -import { IS_CE_EDITION, apiPrefix } from '@/config' +import { API_PREFIX, IS_CE_EDITION } from '@/config' import Button from '@/app/components/base/button' import { login, oauth } from '@/service/common' -import I18n from '@/context/i18n' import { getPurifyHref } from '@/utils' const validEmailReg = /^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$/ @@ -65,7 +63,6 @@ function reducer(state: IState, action: IAction) { const NormalForm = () => { const { t } = useTranslation() const router = useRouter() - const { locale } = useContext(I18n) const [state, dispatch] = useReducer(reducer, { formValid: false, @@ -157,7 +154,7 @@ const NormalForm = () => { {!IS_CE_EDITION && (
- +