Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor: remove `NEXT_PUBLIC_SERVICE_MODE` env and use server by default (#10017)

Arvin Xuf2ab2fcef6a7
diff --git a/.env.desktop b/.env.desktop
index c39de24a65f..1e00b9cccad 100644
--- a/.env.desktop
+++ b/.env.desktop
@@ -4,6 +4,5 @@ FEATURE_FLAGS=-check_updates,+pin_list
KEY_VAULTS_SECRET=oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE=
DATABASE_URL=postgresql://postgres@localhost:5432/postgres
SEARCH_PROVIDERS=search1api
-NEXT_PUBLIC_SERVICE_MODE='server'
NEXT_PUBLIC_IS_DESKTOP_APP=1
-NEXT_PUBLIC_ENABLE_NEXT_AUTH=0
\ No newline at end of file
+NEXT_PUBLIC_ENABLE_NEXT_AUTH=0
diff --git a/.env.example b/.env.example
index 5b3ef3600ae..3500cddf133 100644
--- a/.env.example
+++ b/.env.example
@@ -273,9 +273,6 @@ OPENAI_API_KEY=sk-xxxxxxxxx
########## Server Database #############
########################################
-# Specify the service mode as server if you want to use the server database
-# NEXT_PUBLIC_SERVICE_MODE=server
-
# Postgres database URL
# DATABASE_URL=postgres://username:password@host:port/database
diff --git a/.env.example.development b/.env.example.development
index 74aae9a496e..72c275f9aef 100644
--- a/.env.example.development
+++ b/.env.example.development
@@ -8,8 +8,6 @@ UNSAFE_SECRET="ww+0igxjGRAAR/eTNFQ55VmhQB5KE5trFZseuntThJs="
UNSAFE_PASSWORD="CHANGE_THIS_PASSWORD_IN_PRODUCTION"
# Core Server Configuration
-# Service mode - set to 'server' for server-side deployment
-NEXT_PUBLIC_SERVICE_MODE=server
# Service Ports Configuration
LOBE_PORT=3010
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index da2cc5dace9..7c04aa0408b 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -14,6 +14,17 @@ jobs:
e2e:
name: Test Web App
runs-on: ubuntu-latest
+ services:
+ postgres:
+ image: paradedb/paradedb:latest
+ env:
+ POSTGRES_PASSWORD: postgres
+ options: >-
+ --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
+
+ ports:
+ - 5432:5432
+
timeout-minutes: 25
steps:
- name: Checkout
@@ -33,6 +44,9 @@ jobs:
- name: Run E2E tests
env:
PORT: 3010
+ DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
+ DATABASE_DRIVER: node
+ KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
run: bun run e2e
- name: Upload Cucumber HTML report (on failure)
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 19ee7811059..6e7055e8303 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -54,7 +54,6 @@ jobs:
env:
DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
DATABASE_DRIVER: node
- NEXT_PUBLIC_SERVICE_MODE: server
KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
S3_PUBLIC_DOMAIN: https://example.com
APP_URL: https://home.com
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index bf173780394..51d2d6bb480 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -165,7 +165,6 @@ jobs:
env:
DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
DATABASE_DRIVER: node
- NEXT_PUBLIC_SERVICE_MODE: server
KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
S3_PUBLIC_DOMAIN: https://example.com
APP_URL: https://home.com
diff --git a/Dockerfile b/Dockerfile
index e50a6f184fd..b06d24c645c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -37,7 +37,6 @@ FROM base AS builder
ARG USE_CN_MIRROR
ARG NEXT_PUBLIC_BASE_PATH
-ARG NEXT_PUBLIC_SERVICE_MODE
ARG NEXT_PUBLIC_ENABLE_NEXT_AUTH
ARG NEXT_PUBLIC_ENABLE_CLERK_AUTH
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
@@ -53,8 +52,7 @@ ARG FEATURE_FLAGS
ENV NEXT_PUBLIC_BASE_PATH="${NEXT_PUBLIC_BASE_PATH}" \
FEATURE_FLAGS="${FEATURE_FLAGS}"
-ENV NEXT_PUBLIC_SERVICE_MODE="${NEXT_PUBLIC_SERVICE_MODE:-server}" \
- NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-1}" \
+ENV NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-1}" \
NEXT_PUBLIC_ENABLE_CLERK_AUTH="${NEXT_PUBLIC_ENABLE_CLERK_AUTH:-0}" \
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="${NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}" \
CLERK_WEBHOOK_SECRET="whsec_xxx" \
diff --git a/package.json b/package.json
index 9c344c102be..9442ba15a22 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,7 @@
"build:analyze": "NODE_OPTIONS=--max-old-space-size=6144 ANALYZE=true next build --webpack",
"build:docker": "npm run prebuild && NODE_OPTIONS=--max-old-space-size=6144 DOCKER=true next build --webpack && npm run build-sitemap",
"prebuild:electron": "cross-env NEXT_PUBLIC_IS_DESKTOP_APP=1 tsx scripts/prebuild.mts",
- "build:electron": "cross-env NODE_OPTIONS=--max-old-space-size=6144 NEXT_PUBLIC_IS_DESKTOP_APP=1 NEXT_PUBLIC_SERVICE_MODE=server next build --webpack",
+ "build:electron": "cross-env NODE_OPTIONS=--max-old-space-size=6144 NEXT_PUBLIC_IS_DESKTOP_APP=1 next build --webpack",
"clean:node_modules": "bash -lc 'set -e; echo \"Removing all node_modules...\"; rm -rf node_modules; pnpm -r exec rm -rf node_modules; rm -rf apps/desktop/node_modules; echo \"All node_modules removed.\"'",
"db:generate": "drizzle-kit generate && npm run db:generate-client && npm run workflow:dbml",
"db:generate-client": "tsx ./scripts/migrateClientDB/compile-migrations.ts",
diff --git a/packages/database/src/core/web-server.ts b/packages/database/src/core/web-server.ts
index 47484a7b7c1..4c4a6299d92 100644
--- a/packages/database/src/core/web-server.ts
+++ b/packages/database/src/core/web-server.ts
@@ -10,7 +10,8 @@ import * as schema from '../schemas';
import { LobeChatDatabase } from '../type';
export const getDBInstance = (): LobeChatDatabase => {
- if (!(process.env.NEXT_PUBLIC_SERVICE_MODE === 'server')) return {} as any;
+ // In test environment, return a mock instance to avoid initialization errors
+ if (process.env.NODE_ENV === 'test') return {} as LobeChatDatabase;
if (!serverDBEnv.KEY_VAULTS_SECRET) {
throw new Error(
diff --git a/scripts/migrateServerDB/errorHint.js b/scripts/migrateServerDB/errorHint.js
index 6b55bd447b5..0eaaeead64c 100644
--- a/scripts/migrateServerDB/errorHint.js
+++ b/scripts/migrateServerDB/errorHint.js
@@ -15,13 +15,7 @@ if you have any other question, please open issue here: https://github.com/lobeh
const DB_FAIL_INIT_HINT = `------------------------------------------------------------------------------------------
⚠️ Database migrate failed due to not find the db instance.
-1) You might not switch to server db mode, please set the env blow and try again:
-
-\`\`\`
-NEXT_PUBLIC_SERVICE_MODE=server
-\`\`\`
-
-2) if you are using docker postgres image, you may need to set DATABASE_DRIVER to node
+if you are using docker postgres image, you may need to set DATABASE_DRIVER to node
\`\`\`
DATABASE_DRIVER=node
diff --git a/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx b/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx
index 0ba18b2dd3c..ae5c02b0ac7 100644
--- a/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx
+++ b/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx
@@ -32,9 +32,6 @@ const TopActions = memo<TopActionProps>(({ tab, isPinned }) => {
useServerConfigStore(featureFlagsSelectors);
const hotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.NavigateToChat));
- // Check if server mode is enabled
- const isServerMode = process.env.NEXT_PUBLIC_SERVICE_MODE === 'server';
-
const isChatActive = tab === SidebarTabKey.Chat && !isPinned;
const isFilesActive = tab === SidebarTabKey.Files;
const isDiscoverActive = tab === SidebarTabKey.Discover;
@@ -69,7 +66,7 @@ const TopActions = memo<TopActionProps>(({ tab, isPinned }) => {
tooltipProps={{ placement: 'right' }}
/>
</Link>
- {enableKnowledgeBase && isServerMode && (
+ {enableKnowledgeBase && (
<Link aria-label={t('tab.knowledgeBase')} href={'/knowledge'}>
<ActionIcon
active={isFilesActive}
diff --git a/src/config/db.ts b/src/config/db.ts
index 197c3b6c4bc..f2d6bc51791 100644
--- a/src/config/db.ts
+++ b/src/config/db.ts
@@ -3,9 +3,6 @@ import { z } from 'zod';
export const getServerDBConfig = () => {
return createEnv({
- client: {
- NEXT_PUBLIC_ENABLED_SERVER_SERVICE: z.boolean(),
- },
runtimeEnv: {
DATABASE_DRIVER: process.env.DATABASE_DRIVER || 'neon',
DATABASE_TEST_URL: process.env.DATABASE_TEST_URL,
@@ -13,8 +10,6 @@ export const getServerDBConfig = () => {
KEY_VAULTS_SECRET: process.env.KEY_VAULTS_SECRET,
- NEXT_PUBLIC_ENABLED_SERVER_SERVICE: process.env.NEXT_PUBLIC_SERVICE_MODE === 'server',
-
REMOVE_GLOBAL_FILE: process.env.DISABLE_REMOVE_GLOBAL_FILE !== '0',
},
server: {
diff --git a/src/libs/next-auth/auth.config.ts b/src/libs/next-auth/auth.config.ts
index 8ceef51bdde..19c26605f9d 100644
--- a/src/libs/next-auth/auth.config.ts
+++ b/src/libs/next-auth/auth.config.ts
@@ -1,6 +1,5 @@
import type { NextAuthConfig } from 'next-auth';
-import { getServerDBConfig } from '@/config/db';
import { getAuthConfig } from '@/envs/auth';
import { LobeNextAuthDbAdapter } from './adapter';
@@ -14,8 +13,6 @@ const {
NEXT_PUBLIC_ENABLE_NEXT_AUTH,
} = getAuthConfig();
-const { NEXT_PUBLIC_ENABLED_SERVER_SERVICE } = getServerDBConfig();
-
export const initSSOProviders = () => {
return NEXT_PUBLIC_ENABLE_NEXT_AUTH
? NEXT_AUTH_SSO_PROVIDERS.split(/[,,]/).map((provider) => {
@@ -30,7 +27,7 @@ export const initSSOProviders = () => {
// Notice this is only an object, not a full Auth.js instance
export default {
- adapter: NEXT_PUBLIC_ENABLED_SERVER_SERVICE ? LobeNextAuthDbAdapter() : undefined,
+ adapter: NEXT_PUBLIC_ENABLE_NEXT_AUTH ? LobeNextAuthDbAdapter() : undefined,
callbacks: {
// Note: Data processing order of callback: authorize --> jwt --> session
async jwt({ token, user }) {
@@ -61,7 +58,7 @@ export default {
secret: NEXT_AUTH_SECRET ?? process.env.AUTH_SECRET,
session: {
// Force use JWT if server service is disabled
- strategy: NEXT_PUBLIC_ENABLED_SERVER_SERVICE ? NEXT_AUTH_SSO_SESSION_STRATEGY : 'jwt',
+ strategy: NEXT_AUTH_SSO_SESSION_STRATEGY,
},
trustHost: process.env?.AUTH_TRUST_HOST ? process.env.AUTH_TRUST_HOST === 'true' : true,
} satisfies NextAuthConfig;