fix(router): use getBaseUrl() helper (#1515)

* fix(router): use getBaseUrl() helper

* add existence check
This commit is contained in:
Vikhyath Mondreti
2025-10-01 10:39:57 -07:00
committed by GitHub
parent 0bf2bce368
commit 4ad9be0836
3 changed files with 7 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
import { getEnv } from '@/lib/env'
import { createLogger } from '@/lib/logs/console/logger'
import { createMcpToolId } from '@/lib/mcp/utils'
import { getBaseUrl } from '@/lib/urls/utils'
import { getAllBlocks } from '@/blocks'
import type { BlockOutput } from '@/blocks/types'
import { BlockType } from '@/executor/consts'
@@ -261,8 +261,7 @@ export class AgentBlockHandler implements BlockHandler {
}
}
const appUrl = getEnv('NEXT_PUBLIC_APP_URL')
const url = new URL(`${appUrl}/api/mcp/tools/discover`)
const url = new URL('/api/mcp/tools/discover', getBaseUrl())
url.searchParams.set('serverId', serverId)
if (context.workspaceId) {
url.searchParams.set('workspaceId', context.workspaceId)
@@ -316,7 +315,7 @@ export class AgentBlockHandler implements BlockHandler {
}
}
const execResponse = await fetch(`${appUrl}/api/mcp/tools/execute`, {
const execResponse = await fetch(`${getBaseUrl()}/api/mcp/tools/execute`, {
method: 'POST',
headers,
body: JSON.stringify({
@@ -640,7 +639,7 @@ export class AgentBlockHandler implements BlockHandler {
) {
logger.info('Using HTTP provider request (browser environment)')
const url = new URL('/api/providers', getEnv('NEXT_PUBLIC_APP_URL') || '')
const url = new URL('/api/providers', getBaseUrl())
const response = await fetch(url.toString(), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },

View File

@@ -1,5 +1,5 @@
import { env } from '@/lib/env'
import { createLogger } from '@/lib/logs/console/logger'
import { getBaseUrl } from '@/lib/urls/utils'
import { generateRouterPrompt } from '@/blocks/blocks/router'
import type { BlockOutput } from '@/blocks/types'
import { BlockType } from '@/executor/consts'
@@ -40,8 +40,7 @@ export class RouterBlockHandler implements BlockHandler {
const providerId = getProviderFromModel(routerConfig.model)
try {
const baseUrl = env.NEXT_PUBLIC_APP_URL || ''
const url = new URL('/api/providers', baseUrl)
const url = new URL('/api/providers', getBaseUrl())
// Create the provider request with proper message formatting
const messages = [{ role: 'user', content: routerConfig.prompt }]

View File

@@ -6,7 +6,7 @@ import { isProd } from '@/lib/environment'
* @returns The base URL string (e.g., 'http://localhost:3000' or 'https://example.com')
*/
export function getBaseUrl(): string {
if (typeof window !== 'undefined') {
if (typeof window !== 'undefined' && window.location?.origin) {
return window.location.origin
}