diff --git a/src/main.rs b/src/main.rs index 4581e90..8a2bd06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,18 +2,23 @@ use axum::{response::Html, routing::get, Router}; use clap::Parser; use dioxus::prelude::*; +const LOCALHOST: &str = "127.0.0.1"; + #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { /// Post used #[arg(short, long, default_value_t = 3000)] - port: u16 + port: u16, + /// IP used + #[arg(short, long, default_value_t = LOCALHOST.to_string())] + address: String, } #[tokio::main] async fn main() { let args = Args::parse(); - let url = format!("127.0.0.1:{}", args.port); + let url = format!("{}:{}", args.address, args.port); let app = Router::new().route("/", get(|| app_endpoint())); let listener = tokio::net::TcpListener::bind(&url).await.unwrap(); axum::serve(listener, app).await.unwrap(); diff --git a/test/test_single_boot.py b/test/test_single_boot.py index eb550d8..51b99b0 100644 --- a/test/test_single_boot.py +++ b/test/test_single_boot.py @@ -4,6 +4,7 @@ import aiohttp from asyncio import create_subprocess_exec from pathlib import Path +from socket import gethostbyname, gethostname from unittest import IsolatedAsyncioTestCase @@ -55,3 +56,11 @@ class SingleBootTC(IsolatedAsyncioTestCase): async with aiohttp.ClientSession() as session: async with session.get(f"http://localhost:{port}") as response: self.assertEqual(response.status, 200) + + async def test_alt_address_boot(self): + """Can it boot off an alternate address?""" + addr = gethostbyname(gethostname()) + await self.servers.create_server("-a", addr) + async with aiohttp.ClientSession() as session: + async with session.get(f"http://{addr}:3000") as response: + self.assertEqual(response.status, 200)