Added the ability to change addresses.
This commit is contained in:
		@@ -2,18 +2,23 @@ use axum::{response::Html, routing::get, Router};
 | 
				
			|||||||
use clap::Parser;
 | 
					use clap::Parser;
 | 
				
			||||||
use dioxus::prelude::*;
 | 
					use dioxus::prelude::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const LOCALHOST: &str = "127.0.0.1";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Parser, Debug)]
 | 
					#[derive(Parser, Debug)]
 | 
				
			||||||
#[command(version, about, long_about = None)]
 | 
					#[command(version, about, long_about = None)]
 | 
				
			||||||
struct Args {
 | 
					struct Args {
 | 
				
			||||||
    /// Post used
 | 
					    /// Post used
 | 
				
			||||||
    #[arg(short, long, default_value_t = 3000)]
 | 
					    #[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]
 | 
					#[tokio::main]
 | 
				
			||||||
async fn main() {
 | 
					async fn main() {
 | 
				
			||||||
    let args = Args::parse();
 | 
					    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 app = Router::new().route("/", get(|| app_endpoint()));
 | 
				
			||||||
    let listener = tokio::net::TcpListener::bind(&url).await.unwrap();
 | 
					    let listener = tokio::net::TcpListener::bind(&url).await.unwrap();
 | 
				
			||||||
    axum::serve(listener, app).await.unwrap();
 | 
					    axum::serve(listener, app).await.unwrap();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ import aiohttp
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from asyncio import create_subprocess_exec
 | 
					from asyncio import create_subprocess_exec
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					from socket import gethostbyname, gethostname
 | 
				
			||||||
from unittest import IsolatedAsyncioTestCase
 | 
					from unittest import IsolatedAsyncioTestCase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,3 +56,11 @@ class SingleBootTC(IsolatedAsyncioTestCase):
 | 
				
			|||||||
        async with aiohttp.ClientSession() as session:
 | 
					        async with aiohttp.ClientSession() as session:
 | 
				
			||||||
            async with session.get(f"http://localhost:{port}") as response:
 | 
					            async with session.get(f"http://localhost:{port}") as response:
 | 
				
			||||||
                self.assertEqual(response.status, 200)
 | 
					                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)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user