Fix API URL handling for Docker deployment

- Replace hardcoded localhost URLs with dynamic host detection from request headers
- Supports both development (localhost:3001) and Docker (localhost:9000 -> 3000) environments
- Uses host header to determine correct protocol and port for internal API calls
- Updated execute-dex, validate, and orders APIs to use dynamic baseUrl
- Ensures proper API communication in containerized environments
This commit is contained in:
mindesbunister
2025-07-16 16:24:26 +02:00
parent fb8d361020
commit befe860188
4 changed files with 25 additions and 6 deletions

View File

@@ -7,10 +7,15 @@ export async function POST(request) {
console.log(`🔍 Validating trade: ${side} ${amount} ${symbol} (USD: ${amountUSD})`)
// Get the base URL from the request or use localhost for development
const host = request.headers.get('host') || 'localhost:3000'
const protocol = host.includes('localhost') ? 'http' : 'https'
const baseUrl = `${protocol}://${host}`
// Fetch real wallet balance from the wallet API
let walletBalance
try {
const walletResponse = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/api/wallet/balance`)
const walletResponse = await fetch(`${baseUrl}/api/wallet/balance`)
const walletData = await walletResponse.json()
if (walletData.success && walletData.wallet) {