personal_website/src/public/mod.rs

26 lines
601 B
Rust
Raw Normal View History

2024-03-23 19:35:31 +00:00
2024-03-23 20:03:16 +00:00
mod routes;
2024-03-23 19:35:31 +00:00
mod templates;
2024-03-23 20:03:16 +00:00
use actix_web::{web, App, HttpServer};
2024-03-23 20:19:00 +00:00
use actix_files as actix_fs;
2024-03-23 19:35:31 +00:00
use crate::cli::CliArgs;
pub(crate) async fn start_actix(cli: &CliArgs) -> anyhow::Result<()> {
let bindip = format!("{}:{}", cli.host, cli.port);
log::info!("Serving an http server at http://{bindip}");
2024-03-23 20:03:16 +00:00
HttpServer::new(|| {
App::new()
2024-03-23 20:19:00 +00:00
.route("/", web::get().to(routes::index)) // index.html
.service(actix_fs::Files::new("/static", "./static").index_file("index.html")) // static directoryh
2024-03-23 20:03:16 +00:00
})
2024-03-23 19:35:31 +00:00
.bind(bindip)?
2024-03-23 20:03:16 +00:00
.run()
.await?;
Ok(())
}