Fixed automatic API port selection