From ea26742f63f2b75e79f5829050e7a8cc664877a0 Mon Sep 17 00:00:00 2001 From: johnny0120 <15564476+johnny0120@users.noreply.github.com> Date: Sat, 10 May 2025 15:29:17 +0800 Subject: [PATCH] fix: use NextJS basePath and WEB_PREFIX to support custom prefix --- web/.env.example | 2 ++ web/README.md | 2 ++ web/app/(commonLayout)/apps/AppCard.tsx | 4 ++-- .../datasets/NewDatasetCard.tsx | 10 +++++----- .../components/app/app-publisher/index.tsx | 6 +++--- .../dataset-config/select-dataset/index.tsx | 3 +-- .../components/app/create-app-modal/index.tsx | 10 +++++----- web/app/components/app/log/index.tsx | 3 +-- web/app/components/app/overview/appCard.tsx | 3 +-- .../app/overview/embedded/index.tsx | 9 ++++----- web/app/components/app/workflow-log/index.tsx | 3 +-- .../base/logo/logo-embedded-chat-avatar.tsx | 4 ++-- .../base/logo/logo-embedded-chat-header.tsx | 4 ++-- web/app/components/base/logo/logo-site.tsx | 4 ++-- .../workplace-selector/index.tsx | 4 ++-- .../edit-workspace-modal/index.tsx | 3 ++- .../invited-modal/invitation-link.tsx | 6 +++--- .../provider-icon/index.tsx | 3 +-- .../components/header/dataset-nav/index.tsx | 3 +-- .../components/tools/add-tool-modal/tools.tsx | 4 ++-- web/app/components/tools/provider/detail.tsx | 6 +++--- .../components/editor/code-editor/index.tsx | 3 ++- .../forgot-password/ChangePasswordForm.tsx | 4 ++-- .../forgot-password/ForgotPasswordForm.tsx | 4 ++-- web/app/init/InitPasswordPopup.tsx | 4 ++-- web/app/install/installForm.tsx | 5 ++--- web/app/layout.tsx | 2 ++ web/config/index.ts | 19 ++++++++++++++++++- web/docker/entrypoint.sh | 2 ++ web/service/base.ts | 13 ++++++------- web/service/fetch.ts | 4 ++-- 31 files changed, 87 insertions(+), 69 deletions(-) diff --git a/web/.env.example b/web/.env.example index 51631c2437..e501df92b5 100644 --- a/web/.env.example +++ b/web/.env.example @@ -6,10 +6,12 @@ NEXT_PUBLIC_EDITION=SELF_HOSTED # different from api or web app domain. # example: http://cloud.dify.ai/console/api NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api +NEXT_PUBLIC_WEB_PREFIX=http://localhost:3000 # 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 +NEXT_PUBLIC_PUBLIC_WEB_PREFIX=http://localhost:3000 # The API PREFIX for MARKETPLACE NEXT_PUBLIC_MARKETPLACE_API_PREFIX=https://marketplace.dify.ai/api/v1 # The URL for MARKETPLACE diff --git a/web/README.md b/web/README.md index 3d9fd2de87..ddb1155264 100644 --- a/web/README.md +++ b/web/README.md @@ -31,10 +31,12 @@ NEXT_PUBLIC_EDITION=SELF_HOSTED # different from api or web app domain. # example: http://cloud.dify.ai/console/api NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api +NEXT_PUBLIC_WEB_PREFIX=http://localhost:3000 # 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 +NEXT_PUBLIC_PUBLIC_WEB_PREFIX=http://localhost:3000 # SENTRY NEXT_PUBLIC_SENTRY_DSN= diff --git a/web/app/(commonLayout)/apps/AppCard.tsx b/web/app/(commonLayout)/apps/AppCard.tsx index 3f8c180c1a..c2ad1f1283 100644 --- a/web/app/(commonLayout)/apps/AppCard.tsx +++ b/web/app/(commonLayout)/apps/AppCard.tsx @@ -16,7 +16,7 @@ import AppsContext, { useAppContext } from '@/context/app-context' import type { HtmlContentProps } from '@/app/components/base/popover' import CustomPopover from '@/app/components/base/popover' import Divider from '@/app/components/base/divider' -import { basePath } from '@/utils/var' +import { WEB_PREFIX } from '@/config' import { getRedirection } from '@/utils/app-redirection' import { useProviderContext } from '@/context/provider-context' import { NEED_REFRESH_APP_LIST_KEY } from '@/config' @@ -217,7 +217,7 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => { try { const { installed_apps }: any = await fetchInstalledAppList(app.id) || {} if (installed_apps?.length > 0) - window.open(`${basePath}/explore/installed/${installed_apps[0].id}`, '_blank') + window.open(`${WEB_PREFIX}/explore/installed/${installed_apps[0].id}`, '_blank') else throw new Error('No app found in Explore') } diff --git a/web/app/(commonLayout)/datasets/NewDatasetCard.tsx b/web/app/(commonLayout)/datasets/NewDatasetCard.tsx index 792d9904da..ddc48c2a6e 100644 --- a/web/app/(commonLayout)/datasets/NewDatasetCard.tsx +++ b/web/app/(commonLayout)/datasets/NewDatasetCard.tsx @@ -1,6 +1,6 @@ 'use client' import { useTranslation } from 'react-i18next' -import { basePath } from '@/utils/var' +import Link from 'next/link' import { RiAddLine, RiArrowRightLine, @@ -18,7 +18,7 @@ const CreateAppCard = (