Skip to content

Commit

Permalink
feat(launch-uri): Open server address in default browser
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbcn committed Feb 26, 2022
1 parent 0952897 commit c5820f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tasklist-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ actix-web = "3.3.3"
actix-web-static-files = "3.0.5"
actix-web-actors = "3.0.0"
sys-info = "0.9.1"
open = "1"
tokio = "1.17.0"

env_logger = "0.9"
log = "0.4"
Expand Down
15 changes: 11 additions & 4 deletions tasklist-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ async fn websocket(req: HttpRequest, stream: web::Payload) -> Result<HttpRespons
)
}

async fn open_server_address() {
open::that("http://localhost:8080").unwrap();
}

pub async fn start() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));

log::info!("starting HTTP server at http://localhost:8080");

HttpServer::new(move || {
let server = HttpServer::new(move || {
let generated = generate();
App::new()
.route("/ws", web::get().to(websocket))
Expand All @@ -34,7 +38,10 @@ pub async fn start() -> std::io::Result<()> {
.wrap(Logger::default())
})
.workers(1)
.bind("127.0.0.1:8080")?
.run()
.await
.bind("localhost:8080")?
.run();

tokio::join!(server, open_server_address());

Ok(())
}

0 comments on commit c5820f8

Please sign in to comment.