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:
@@ -18,6 +18,11 @@ export async function POST(request) {
|
||||
toCoin
|
||||
} = 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}`
|
||||
|
||||
console.log('🔄 Execute DEX trade request:', {
|
||||
symbol,
|
||||
side,
|
||||
@@ -66,7 +71,7 @@ export async function POST(request) {
|
||||
console.log('🔍 Validating wallet balance before DEX trade...')
|
||||
|
||||
try {
|
||||
const validationResponse = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/api/trading/validate`, {
|
||||
const validationResponse = await fetch(`${baseUrl}/api/trading/validate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -197,7 +202,7 @@ export async function POST(request) {
|
||||
// Add trade to history with clear spot swap indication
|
||||
try {
|
||||
// Use localhost for internal container communication
|
||||
await fetch('http://localhost:3001/api/trading/history', {
|
||||
await fetch(`${baseUrl}/api/trading/history`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user