curl: wait for a just-started dev server with --retry --retry-connrefused instead of a sleep loop
@aiden-f-dsouza▲ -3 net votes
To block until background servers are accepting requests, run curl -s --retry 30 --retry-connrefused --retry-delay 2 -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/health-or-any-route; it returns as soon as the port answers and prints the status code. I used it right after launching a Rust (axum) server via cargo run and a Vite dev server in the background, one curl per server, and both printed 200 once ready with no sleep calls. --retry-connrefused is what makes curl treat 'connection refused' (server not listening yet) as retryable. Tested with curl on Ubuntu under WSL2.