Bug Report: Hardcoded Server Address Makes Docker and Cloud Deployment Impossible
Description
The server bind address and port are hardcoded in main.rs as 127.0.0.1:8000.
In a Docker container, 127.0.0.1 binds only to the container's loopback
interface, making the server unreachable from outside the container. Cloud
platforms (Railway, Render, Fly.io, Heroku) inject the required port via the
$PORT environment variable, which the application ignores. The application is
entirely undeployable in containerised or cloud environments without modifying
source code.
Steps to Reproduce
- Build the Docker image:
docker build -t rust-tune .
- Run it:
docker run -p 8080:8000 rust-tune
- Access
http://localhost:8080/ from the host machine.
- Observe connection refused because the server is bound to loopback only.
Root Cause
HttpServer::new(...).bind("127.0.0.1:8000") is hardcoded with no
std::env::var("PORT") or std::env::var("HOST") lookup.
Impact
The project cannot be deployed to any cloud hosting service or Docker-based
infrastructure, limiting it to local development only.
Proposed Fix
Read host and port from environment variables with sensible defaults:
use std::env;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let host = env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string());
let port = env::var("PORT").unwrap_or_else(|_| "8000".to_string());
let bind_addr = format!("{}:{}", host, port);
HttpServer::new(|| App::new().service(index))
.bind(&bind_addr)?
.run()
.await
}
Bug Report: Hardcoded Server Address Makes Docker and Cloud Deployment Impossible
Description
The server bind address and port are hardcoded in
main.rsas127.0.0.1:8000.In a Docker container,
127.0.0.1binds only to the container's loopbackinterface, making the server unreachable from outside the container. Cloud
platforms (Railway, Render, Fly.io, Heroku) inject the required port via the
$PORTenvironment variable, which the application ignores. The application isentirely undeployable in containerised or cloud environments without modifying
source code.
Steps to Reproduce
docker build -t rust-tune .docker run -p 8080:8000 rust-tunehttp://localhost:8080/from the host machine.Root Cause
HttpServer::new(...).bind("127.0.0.1:8000")is hardcoded with nostd::env::var("PORT")orstd::env::var("HOST")lookup.Impact
The project cannot be deployed to any cloud hosting service or Docker-based
infrastructure, limiting it to local development only.
Proposed Fix
Read host and port from environment variables with sensible defaults: