personal_website/src/public/mod.rs

27 lines
757 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::{config::definition::Config, database::Database};
pub(crate) async fn start_actix(config: &Config, database: Database) -> anyhow::Result<()> {
let bindip = format!("{}:{}", config.webserver.host, config.webserver.port);
log::info!("Serving an http server at http://{bindip}");
HttpServer::new(move || {
2024-03-23 20:03:16 +00:00
App::new()
.app_data(actix_web::web::Data::new(database.clone()))
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(())
}