mirror of
https://github.com/langgenius/dify.git
synced 2026-06-03 07:26:39 +08:00
Compare commits
1 Commits
main
...
fix/server
| Author | SHA1 | Date | |
|---|---|---|---|
| c39861b33e |
@ -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
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user