add support for crlf, add support for changing port

This commit is contained in:
りき萌 2023-08-28 15:30:15 +02:00
parent 4b74b3930b
commit eb79cf8cab
6 changed files with 34 additions and 13 deletions

View file

@ -249,14 +249,14 @@ pub fn regenerate_or_report_error(paths: &Paths<'_>) {
}
}
pub async fn web_server() -> anyhow::Result<()> {
pub async fn web_server(port: u16) -> anyhow::Result<()> {
let app = Router::new().nest_service("/", ServeDir::new("target/site"));
#[cfg(debug_assertions)]
let app = app.layer(LiveReloadLayer::new());
info!("serving on port 8080");
Ok(axum::Server::bind(&([0, 0, 0, 0], 8080).into())
info!("serving on port {port}");
Ok(axum::Server::bind(&([0, 0, 0, 0], port).into())
.serve(app.into_make_service())
.await?)
}

View file

@ -28,9 +28,9 @@ pub enum Command {
#[derive(Args)]
pub struct GenerateArgs {
/// Start a web server serving the static files. Useful with `cargo watch`.
/// Start a web server serving the static files on the given port. Useful with `cargo watch`.
#[clap(short, long)]
pub serve: bool,
pub serve: Option<u16>,
}
#[derive(Args)]

View file

@ -35,8 +35,8 @@ async fn fallible_main() -> anyhow::Result<()> {
regenerate_or_report_error(&paths);
if regenerate_args.serve {
generate::web_server().await?;
if let Some(port) = regenerate_args.serve {
generate::web_server(port).await?;
}
}