mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-26 13:19:34 +07:00
♻️ refactor: remove NEXT_PUBLIC_SERVICE_MODE env and use server by default (#10017)
* remove NEXT_PUBLIC_SERVICE_MODE * update * fix tests * update e2e workflow * update config * Rename DATABASE_TEST_URL to DATABASE_URL
This commit is contained in:
@@ -4,6 +4,5 @@ FEATURE_FLAGS=-check_updates,+pin_list
|
|||||||
KEY_VAULTS_SECRET=oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE=
|
KEY_VAULTS_SECRET=oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE=
|
||||||
DATABASE_URL=postgresql://postgres@localhost:5432/postgres
|
DATABASE_URL=postgresql://postgres@localhost:5432/postgres
|
||||||
SEARCH_PROVIDERS=search1api
|
SEARCH_PROVIDERS=search1api
|
||||||
NEXT_PUBLIC_SERVICE_MODE='server'
|
|
||||||
NEXT_PUBLIC_IS_DESKTOP_APP=1
|
NEXT_PUBLIC_IS_DESKTOP_APP=1
|
||||||
NEXT_PUBLIC_ENABLE_NEXT_AUTH=0
|
NEXT_PUBLIC_ENABLE_NEXT_AUTH=0
|
||||||
|
|||||||
@@ -273,9 +273,6 @@ OPENAI_API_KEY=sk-xxxxxxxxx
|
|||||||
########## Server Database #############
|
########## Server Database #############
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
# Specify the service mode as server if you want to use the server database
|
|
||||||
# NEXT_PUBLIC_SERVICE_MODE=server
|
|
||||||
|
|
||||||
# Postgres database URL
|
# Postgres database URL
|
||||||
# DATABASE_URL=postgres://username:password@host:port/database
|
# DATABASE_URL=postgres://username:password@host:port/database
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ UNSAFE_SECRET="ww+0igxjGRAAR/eTNFQ55VmhQB5KE5trFZseuntThJs="
|
|||||||
UNSAFE_PASSWORD="CHANGE_THIS_PASSWORD_IN_PRODUCTION"
|
UNSAFE_PASSWORD="CHANGE_THIS_PASSWORD_IN_PRODUCTION"
|
||||||
|
|
||||||
# Core Server Configuration
|
# Core Server Configuration
|
||||||
# Service mode - set to 'server' for server-side deployment
|
|
||||||
NEXT_PUBLIC_SERVICE_MODE=server
|
|
||||||
|
|
||||||
# Service Ports Configuration
|
# Service Ports Configuration
|
||||||
LOBE_PORT=3010
|
LOBE_PORT=3010
|
||||||
|
|||||||
14
.github/workflows/e2e.yml
vendored
14
.github/workflows/e2e.yml
vendored
@@ -14,6 +14,17 @@ jobs:
|
|||||||
e2e:
|
e2e:
|
||||||
name: Test Web App
|
name: Test Web App
|
||||||
runs-on: ubuntu-latest
|
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
|
timeout-minutes: 25
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -33,6 +44,9 @@ jobs:
|
|||||||
- name: Run E2E tests
|
- name: Run E2E tests
|
||||||
env:
|
env:
|
||||||
PORT: 3010
|
PORT: 3010
|
||||||
|
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
|
||||||
|
DATABASE_DRIVER: node
|
||||||
|
KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
|
||||||
run: bun run e2e
|
run: bun run e2e
|
||||||
|
|
||||||
- name: Upload Cucumber HTML report (on failure)
|
- name: Upload Cucumber HTML report (on failure)
|
||||||
|
|||||||
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@@ -54,7 +54,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
|
DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
|
||||||
DATABASE_DRIVER: node
|
DATABASE_DRIVER: node
|
||||||
NEXT_PUBLIC_SERVICE_MODE: server
|
|
||||||
KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
|
KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
|
||||||
S3_PUBLIC_DOMAIN: https://example.com
|
S3_PUBLIC_DOMAIN: https://example.com
|
||||||
APP_URL: https://home.com
|
APP_URL: https://home.com
|
||||||
|
|||||||
1
.github/workflows/test.yml
vendored
1
.github/workflows/test.yml
vendored
@@ -165,7 +165,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
|
DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
|
||||||
DATABASE_DRIVER: node
|
DATABASE_DRIVER: node
|
||||||
NEXT_PUBLIC_SERVICE_MODE: server
|
|
||||||
KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
|
KEY_VAULTS_SECRET: LA7n9k3JdEcbSgml2sxfw+4TV1AzaaFU5+R176aQz4s=
|
||||||
S3_PUBLIC_DOMAIN: https://example.com
|
S3_PUBLIC_DOMAIN: https://example.com
|
||||||
APP_URL: https://home.com
|
APP_URL: https://home.com
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ FROM base AS builder
|
|||||||
|
|
||||||
ARG USE_CN_MIRROR
|
ARG USE_CN_MIRROR
|
||||||
ARG NEXT_PUBLIC_BASE_PATH
|
ARG NEXT_PUBLIC_BASE_PATH
|
||||||
ARG NEXT_PUBLIC_SERVICE_MODE
|
|
||||||
ARG NEXT_PUBLIC_ENABLE_NEXT_AUTH
|
ARG NEXT_PUBLIC_ENABLE_NEXT_AUTH
|
||||||
ARG NEXT_PUBLIC_ENABLE_CLERK_AUTH
|
ARG NEXT_PUBLIC_ENABLE_CLERK_AUTH
|
||||||
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
|
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
|
||||||
@@ -53,8 +52,7 @@ ARG FEATURE_FLAGS
|
|||||||
ENV NEXT_PUBLIC_BASE_PATH="${NEXT_PUBLIC_BASE_PATH}" \
|
ENV NEXT_PUBLIC_BASE_PATH="${NEXT_PUBLIC_BASE_PATH}" \
|
||||||
FEATURE_FLAGS="${FEATURE_FLAGS}"
|
FEATURE_FLAGS="${FEATURE_FLAGS}"
|
||||||
|
|
||||||
ENV NEXT_PUBLIC_SERVICE_MODE="${NEXT_PUBLIC_SERVICE_MODE:-server}" \
|
ENV NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-1}" \
|
||||||
NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-1}" \
|
|
||||||
NEXT_PUBLIC_ENABLE_CLERK_AUTH="${NEXT_PUBLIC_ENABLE_CLERK_AUTH:-0}" \
|
NEXT_PUBLIC_ENABLE_CLERK_AUTH="${NEXT_PUBLIC_ENABLE_CLERK_AUTH:-0}" \
|
||||||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="${NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}" \
|
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="${NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}" \
|
||||||
CLERK_WEBHOOK_SECRET="whsec_xxx" \
|
CLERK_WEBHOOK_SECRET="whsec_xxx" \
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
"build:analyze": "NODE_OPTIONS=--max-old-space-size=6144 ANALYZE=true next build --webpack",
|
"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",
|
"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",
|
"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.\"'",
|
"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": "drizzle-kit generate && npm run db:generate-client && npm run workflow:dbml",
|
||||||
"db:generate-client": "tsx ./scripts/migrateClientDB/compile-migrations.ts",
|
"db:generate-client": "tsx ./scripts/migrateClientDB/compile-migrations.ts",
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ import * as schema from '../schemas';
|
|||||||
import { LobeChatDatabase } from '../type';
|
import { LobeChatDatabase } from '../type';
|
||||||
|
|
||||||
export const getDBInstance = (): LobeChatDatabase => {
|
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) {
|
if (!serverDBEnv.KEY_VAULTS_SECRET) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
@@ -15,13 +15,7 @@ if you have any other question, please open issue here: https://github.com/lobeh
|
|||||||
const DB_FAIL_INIT_HINT = `------------------------------------------------------------------------------------------
|
const DB_FAIL_INIT_HINT = `------------------------------------------------------------------------------------------
|
||||||
⚠️ Database migrate failed due to not find the db instance.
|
⚠️ 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:
|
if you are using docker postgres image, you may need to set DATABASE_DRIVER to node
|
||||||
|
|
||||||
\`\`\`
|
|
||||||
NEXT_PUBLIC_SERVICE_MODE=server
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
2) if you are using docker postgres image, you may need to set DATABASE_DRIVER to node
|
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
DATABASE_DRIVER=node
|
DATABASE_DRIVER=node
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ const TopActions = memo<TopActionProps>(({ tab, isPinned }) => {
|
|||||||
useServerConfigStore(featureFlagsSelectors);
|
useServerConfigStore(featureFlagsSelectors);
|
||||||
const hotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.NavigateToChat));
|
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 isChatActive = tab === SidebarTabKey.Chat && !isPinned;
|
||||||
const isFilesActive = tab === SidebarTabKey.Files;
|
const isFilesActive = tab === SidebarTabKey.Files;
|
||||||
const isDiscoverActive = tab === SidebarTabKey.Discover;
|
const isDiscoverActive = tab === SidebarTabKey.Discover;
|
||||||
@@ -69,7 +66,7 @@ const TopActions = memo<TopActionProps>(({ tab, isPinned }) => {
|
|||||||
tooltipProps={{ placement: 'right' }}
|
tooltipProps={{ placement: 'right' }}
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
{enableKnowledgeBase && isServerMode && (
|
{enableKnowledgeBase && (
|
||||||
<Link aria-label={t('tab.knowledgeBase')} href={'/knowledge'}>
|
<Link aria-label={t('tab.knowledgeBase')} href={'/knowledge'}>
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
active={isFilesActive}
|
active={isFilesActive}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
export const getServerDBConfig = () => {
|
export const getServerDBConfig = () => {
|
||||||
return createEnv({
|
return createEnv({
|
||||||
client: {
|
|
||||||
NEXT_PUBLIC_ENABLED_SERVER_SERVICE: z.boolean(),
|
|
||||||
},
|
|
||||||
runtimeEnv: {
|
runtimeEnv: {
|
||||||
DATABASE_DRIVER: process.env.DATABASE_DRIVER || 'neon',
|
DATABASE_DRIVER: process.env.DATABASE_DRIVER || 'neon',
|
||||||
DATABASE_TEST_URL: process.env.DATABASE_TEST_URL,
|
DATABASE_TEST_URL: process.env.DATABASE_TEST_URL,
|
||||||
@@ -13,8 +10,6 @@ export const getServerDBConfig = () => {
|
|||||||
|
|
||||||
KEY_VAULTS_SECRET: process.env.KEY_VAULTS_SECRET,
|
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',
|
REMOVE_GLOBAL_FILE: process.env.DISABLE_REMOVE_GLOBAL_FILE !== '0',
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { NextAuthConfig } from 'next-auth';
|
import type { NextAuthConfig } from 'next-auth';
|
||||||
|
|
||||||
import { getServerDBConfig } from '@/config/db';
|
|
||||||
import { getAuthConfig } from '@/envs/auth';
|
import { getAuthConfig } from '@/envs/auth';
|
||||||
|
|
||||||
import { LobeNextAuthDbAdapter } from './adapter';
|
import { LobeNextAuthDbAdapter } from './adapter';
|
||||||
@@ -14,8 +13,6 @@ const {
|
|||||||
NEXT_PUBLIC_ENABLE_NEXT_AUTH,
|
NEXT_PUBLIC_ENABLE_NEXT_AUTH,
|
||||||
} = getAuthConfig();
|
} = getAuthConfig();
|
||||||
|
|
||||||
const { NEXT_PUBLIC_ENABLED_SERVER_SERVICE } = getServerDBConfig();
|
|
||||||
|
|
||||||
export const initSSOProviders = () => {
|
export const initSSOProviders = () => {
|
||||||
return NEXT_PUBLIC_ENABLE_NEXT_AUTH
|
return NEXT_PUBLIC_ENABLE_NEXT_AUTH
|
||||||
? NEXT_AUTH_SSO_PROVIDERS.split(/[,,]/).map((provider) => {
|
? 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
|
// Notice this is only an object, not a full Auth.js instance
|
||||||
export default {
|
export default {
|
||||||
adapter: NEXT_PUBLIC_ENABLED_SERVER_SERVICE ? LobeNextAuthDbAdapter() : undefined,
|
adapter: NEXT_PUBLIC_ENABLE_NEXT_AUTH ? LobeNextAuthDbAdapter() : undefined,
|
||||||
callbacks: {
|
callbacks: {
|
||||||
// Note: Data processing order of callback: authorize --> jwt --> session
|
// Note: Data processing order of callback: authorize --> jwt --> session
|
||||||
async jwt({ token, user }) {
|
async jwt({ token, user }) {
|
||||||
@@ -61,7 +58,7 @@ export default {
|
|||||||
secret: NEXT_AUTH_SECRET ?? process.env.AUTH_SECRET,
|
secret: NEXT_AUTH_SECRET ?? process.env.AUTH_SECRET,
|
||||||
session: {
|
session: {
|
||||||
// Force use JWT if server service is disabled
|
// 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,
|
trustHost: process.env?.AUTH_TRUST_HOST ? process.env.AUTH_TRUST_HOST === 'true' : true,
|
||||||
} satisfies NextAuthConfig;
|
} satisfies NextAuthConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user