mirror of
https://github.com/langgenius/dify.git
synced 2026-06-07 16:13:59 +08:00
fix: configure server console api url (#36958)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
86af36429d
commit
1b37635f92
@ -13,6 +13,7 @@
|
||||
|
||||
# Core service URLs
|
||||
CONSOLE_API_URL=
|
||||
SERVER_CONSOLE_API_URL=http://api:5001
|
||||
CONSOLE_WEB_URL=
|
||||
SERVICE_API_URL=
|
||||
TRIGGER_URL=http://localhost
|
||||
|
||||
@ -80,7 +80,8 @@ The root `.env.example` file contains the essential startup settings. Optional a
|
||||
|
||||
1. **Common Variables**:
|
||||
|
||||
- `CONSOLE_API_URL`, `CONSOLE_WEB_URL`, `SERVICE_API_URL`, `APP_API_URL`, `APP_WEB_URL`: URLs for the API and frontend services.
|
||||
- `CONSOLE_API_URL`, `CONSOLE_WEB_URL`, `SERVICE_API_URL`, `APP_API_URL`, `APP_WEB_URL`: public URLs for the API and frontend services.
|
||||
- `SERVER_CONSOLE_API_URL`: internal URL used by the web service for server-side console API requests. Keep the default `http://api:5001` for standard Docker Compose deployments, and only change it when your web service must reach the API through a different internal address.
|
||||
- `FILES_URL`, `INTERNAL_FILES_URL`: Public and internal base URLs for file downloads and previews.
|
||||
- `ENDPOINT_URL_TEMPLATE`, `NEXT_PUBLIC_SOCKET_URL`, `TRIGGER_URL`: Additional service URLs.
|
||||
|
||||
|
||||
@ -376,6 +376,7 @@ services:
|
||||
- ./.env
|
||||
environment:
|
||||
CONSOLE_API_URL: ${CONSOLE_API_URL:-}
|
||||
SERVER_CONSOLE_API_URL: ${SERVER_CONSOLE_API_URL:-http://api:5001}
|
||||
APP_API_URL: ${APP_API_URL:-}
|
||||
AMPLITUDE_API_KEY: ${AMPLITUDE_API_KEY:-}
|
||||
NEXT_PUBLIC_COOKIE_DOMAIN: ${NEXT_PUBLIC_COOKIE_DOMAIN:-}
|
||||
|
||||
@ -382,6 +382,7 @@ services:
|
||||
- ./.env
|
||||
environment:
|
||||
CONSOLE_API_URL: ${CONSOLE_API_URL:-}
|
||||
SERVER_CONSOLE_API_URL: ${SERVER_CONSOLE_API_URL:-http://api:5001}
|
||||
APP_API_URL: ${APP_API_URL:-}
|
||||
AMPLITUDE_API_KEY: ${AMPLITUDE_API_KEY:-}
|
||||
NEXT_PUBLIC_COOKIE_DOMAIN: ${NEXT_PUBLIC_COOKIE_DOMAIN:-}
|
||||
|
||||
43
web/config/__tests__/server.spec.ts
Normal file
43
web/config/__tests__/server.spec.ts
Normal file
@ -0,0 +1,43 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.mock('server-only', () => ({}))
|
||||
|
||||
const importServerConfig = async () => {
|
||||
vi.resetModules()
|
||||
return import('../server')
|
||||
}
|
||||
|
||||
describe('server config', () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs()
|
||||
})
|
||||
|
||||
it('should prefer the server-only console API URL for server requests', async () => {
|
||||
vi.stubEnv('SERVER_CONSOLE_API_URL', 'http://api:5001')
|
||||
vi.stubEnv('CONSOLE_API_URL', 'https://console.example.com')
|
||||
|
||||
const { SERVER_CONSOLE_API_PREFIX } = await importServerConfig()
|
||||
|
||||
expect(SERVER_CONSOLE_API_PREFIX).toBe('http://api:5001/console/api')
|
||||
})
|
||||
|
||||
it('should fall back to the public console API URL when no server-only URL is configured', async () => {
|
||||
vi.stubEnv('SERVER_CONSOLE_API_URL', '')
|
||||
vi.stubEnv('CONSOLE_API_URL', 'https://console.example.com')
|
||||
|
||||
const { SERVER_CONSOLE_API_PREFIX } = await importServerConfig()
|
||||
|
||||
expect(SERVER_CONSOLE_API_PREFIX).toBe('https://console.example.com/console/api')
|
||||
})
|
||||
|
||||
it('should remain unconfigured when both server URLs are empty', async () => {
|
||||
vi.stubEnv('SERVER_CONSOLE_API_URL', '')
|
||||
vi.stubEnv('CONSOLE_API_URL', '')
|
||||
|
||||
const { SERVER_CONSOLE_API_PREFIX } = await importServerConfig()
|
||||
|
||||
expect(SERVER_CONSOLE_API_PREFIX).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@ -5,6 +5,8 @@ import 'server-only'
|
||||
const withoutTrailingSlash = (value: string) => value.endsWith('/') ? value.slice(0, -1) : value
|
||||
|
||||
// Server-side requests need the origin; browser requests should keep using NEXT_PUBLIC_API_PREFIX.
|
||||
export const SERVER_CONSOLE_API_PREFIX = env.CONSOLE_API_URL
|
||||
? `${withoutTrailingSlash(env.CONSOLE_API_URL)}/console/api`
|
||||
const serverConsoleApiUrl = env.SERVER_CONSOLE_API_URL || env.CONSOLE_API_URL
|
||||
|
||||
export const SERVER_CONSOLE_API_PREFIX = serverConsoleApiUrl
|
||||
? `${withoutTrailingSlash(serverConsoleApiUrl)}/console/api`
|
||||
: undefined
|
||||
|
||||
@ -161,6 +161,7 @@ const clientSchema = {
|
||||
export const env = createEnv({
|
||||
server: {
|
||||
CONSOLE_API_URL: z.string().optional(),
|
||||
SERVER_CONSOLE_API_URL: z.string().optional(),
|
||||
/**
|
||||
* Maximum length of segmentation tokens for indexing
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user