mirror of
https://github.com/langgenius/dify.git
synced 2026-06-07 00:20:06 +08:00
1b37635f92
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
// @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()
|
|
})
|
|
})
|