Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions apps/sim/executor/handlers/agent/agent-handler.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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' },
Expand Down
5 changes: 2 additions & 3 deletions apps/sim/executor/handlers/router/router-handler.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 }]
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/urls/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down