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

@@ -2,6 +2,9 @@
const testTradeValidation = async () => {
console.log('🧪 Testing trade validation with fixed amountUSD...')
// Use port 9000 for Docker or 3001 for local dev
const apiUrl = process.env.DOCKER_MODE ? 'http://localhost:9000' : 'http://localhost:3001'
const tradeData = {
symbol: 'USDCUSD',
side: 'BUY',
@@ -11,10 +14,11 @@ const testTradeValidation = async () => {
tradingPair: 'USDCUSD/USDC'
}
console.log('🚀 Sending test trade:', tradeData)
console.log('🚀 Sending test trade to:', apiUrl)
console.log('🚀 Trade data:', tradeData)
try {
const response = await fetch('http://localhost:3001/api/trading/execute-dex', {
const response = await fetch(`${apiUrl}/api/trading/execute-dex`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(tradeData)