lyrs/src/webserver.rs

24 lines
572 B
Rust
Raw Normal View History

2024-05-15 16:48:23 -05:00
use std::io;
2024-05-14 14:30:03 -05:00
use crate::{prelude::*, tailwind};
use axum::{serve, Router};
2024-05-15 16:48:23 -05:00
#[instrument(skip(router))]
pub async fn webserver(
router: Router,
with_watchers: bool,
host: Option<&str>,
port: Option<u16>,
) -> Result<(), io::Error> {
2024-05-14 15:33:49 -05:00
if with_watchers {
tokio::spawn(async move { tailwind::start_watcher() });
}
2024-05-14 14:30:03 -05:00
2024-05-15 16:48:23 -05:00
let listener = tokio::net::TcpListener::bind((host.unwrap_or("::1"), port.unwrap_or(3000)))
.await
.unwrap();
let addr = listener.local_addr()?;
info!(%addr);
2024-05-14 14:30:03 -05:00
Ok(serve(listener, router).await?)
}