Skip to content

Commit 4ad9be0

Browse files
fix(router): use getBaseUrl() helper (#1515)
* fix(router): use getBaseUrl() helper * add existence check
1 parent 0bf2bce commit 4ad9be0

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { getEnv } from '@/lib/env'
21
import { createLogger } from '@/lib/logs/console/logger'
32
import { createMcpToolId } from '@/lib/mcp/utils'
3+
import { getBaseUrl } from '@/lib/urls/utils'
44
import { getAllBlocks } from '@/blocks'
55
import type { BlockOutput } from '@/blocks/types'
66
import { BlockType } from '@/executor/consts'
@@ -261,8 +261,7 @@ export class AgentBlockHandler implements BlockHandler {
261261
}
262262
}
263263

264-
const appUrl = getEnv('NEXT_PUBLIC_APP_URL')
265-
const url = new URL(`${appUrl}/api/mcp/tools/discover`)
264+
const url = new URL('/api/mcp/tools/discover', getBaseUrl())
266265
url.searchParams.set('serverId', serverId)
267266
if (context.workspaceId) {
268267
url.searchParams.set('workspaceId', context.workspaceId)
@@ -316,7 +315,7 @@ export class AgentBlockHandler implements BlockHandler {
316315
}
317316
}
318317

319-
const execResponse = await fetch(`${appUrl}/api/mcp/tools/execute`, {
318+
const execResponse = await fetch(`${getBaseUrl()}/api/mcp/tools/execute`, {
320319
method: 'POST',
321320
headers,
322321
body: JSON.stringify({
@@ -640,7 +639,7 @@ export class AgentBlockHandler implements BlockHandler {
640639
) {
641640
logger.info('Using HTTP provider request (browser environment)')
642641

643-
const url = new URL('/api/providers', getEnv('NEXT_PUBLIC_APP_URL') || '')
642+
const url = new URL('/api/providers', getBaseUrl())
644643
const response = await fetch(url.toString(), {
645644
method: 'POST',
646645
headers: { 'Content-Type': 'application/json' },

apps/sim/executor/handlers/router/router-handler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { env } from '@/lib/env'
21
import { createLogger } from '@/lib/logs/console/logger'
2+
import { getBaseUrl } from '@/lib/urls/utils'
33
import { generateRouterPrompt } from '@/blocks/blocks/router'
44
import type { BlockOutput } from '@/blocks/types'
55
import { BlockType } from '@/executor/consts'
@@ -40,8 +40,7 @@ export class RouterBlockHandler implements BlockHandler {
4040
const providerId = getProviderFromModel(routerConfig.model)
4141

4242
try {
43-
const baseUrl = env.NEXT_PUBLIC_APP_URL || ''
44-
const url = new URL('/api/providers', baseUrl)
43+
const url = new URL('/api/providers', getBaseUrl())
4544

4645
// Create the provider request with proper message formatting
4746
const messages = [{ role: 'user', content: routerConfig.prompt }]

apps/sim/lib/urls/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { isProd } from '@/lib/environment'
66
* @returns The base URL string (e.g., 'http://localhost:3000' or 'https://example.com')
77
*/
88
export function getBaseUrl(): string {
9-
if (typeof window !== 'undefined') {
9+
if (typeof window !== 'undefined' && window.location?.origin) {
1010
return window.location.origin
1111
}
1212

0 commit comments

Comments
 (0)