Skip to content

Bug: server binds to hardcoded 127.0.0.1:8000 with no env var support, Docker deployment broken #97

Description

@anshul23102

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

  1. Build the Docker image: docker build -t rust-tune .
  2. Run it: docker run -p 8080:8000 rust-tune
  3. Access http://localhost:8080/ from the host machine.
  4. 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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions