From e22a18c3648a84fa882191f802f4b461789119dc Mon Sep 17 00:00:00 2001 From: azw Date: Fri, 10 Nov 2023 14:01:10 +0000 Subject: [PATCH] 1 --- f9/src/app.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/f9/src/app.rs b/f9/src/app.rs index 8bf41b5..1d46b51 100644 --- a/f9/src/app.rs +++ b/f9/src/app.rs @@ -5,7 +5,7 @@ use std::time::Duration; use tokio::runtime::Runtime; use actix_web::{dev::ServerHandle, middleware, rt, web, HttpRequest, HttpServer}; use actix_web::App as WebApp; -use std::{sync::mpsc, thread, time}; +use std::{sync::mpsc, thread}; use r9_macro::SharedFromSelf; use r9_macro_derive::SharedFromSelf; @@ -15,6 +15,7 @@ pub trait UserApp { fn init(&mut self); fn update(&mut self); fn uninit(&mut self); + fn get_http_listen_port(&self) -> i32; } #[derive(SharedFromSelf)] @@ -27,17 +28,12 @@ pub struct App { user_app: Option>>, } -async fn index(req: HttpRequest) -> &'static str { - "Hello world!asaaa" -} - -async fn run_app(tx: mpsc::Sender) -> std::io::Result<()> { +async fn run_app(port: u16, tx: mpsc::Sender) -> std::io::Result<()> { let server = HttpServer::new(|| { WebApp::new() .service(web::resource("/index.html").to(|| async { "Hello world!" })) - .service(web::resource("/").to(index)) }) - .bind(("127.0.0.1", 8080))? + .bind(("0.0.0.0", port))? .workers(2) .run(); @@ -133,8 +129,9 @@ impl App { fn init_http_server(&mut self) { let (tx, _) = mpsc::channel(); + let port = self.user_app.as_ref().unwrap().borrow().get_http_listen_port() as u16; thread::spawn(move || { - let server_future = run_app(tx); + let server_future = run_app(port, tx); rt::System::new().block_on(server_future) }); }