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

@@ -106,6 +106,11 @@ export async function POST(request) {
const body = await request.json()
const { action, orderId, ...orderData } = body
// Get the base URL from the request
const host = request.headers.get('host') || 'localhost:3000'
const protocol = host.includes('localhost') ? 'http' : 'https'
const baseUrl = `${protocol}://${host}`
if (action === 'add') {
// Load existing orders
const pendingOrders = loadPendingOrders()
@@ -187,7 +192,7 @@ export async function POST(request) {
try {
// Execute the trade by calling the trading API
const tradeResponse = await fetch('http://localhost:3000/api/trading', {
const tradeResponse = await fetch(`${baseUrl}/api/trading`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({