personal_website/src/web/mod.rs

29 lines
952 B
Rust
Raw Normal View History

2024-03-30 15:06:34 +00:00
pub mod routes;
pub mod templates;
2024-03-23 19:35:31 +00:00
2024-03-28 00:17:44 +00:00
use std::sync::Mutex;
2024-03-30 15:06:34 +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()
2024-03-28 00:17:44 +00:00
.app_data(actix_web::web::Data::new(Mutex::new(database.clone())))
2024-03-23 20:19:00 +00:00
.route("/", web::get().to(routes::index)) // index.html
2024-03-30 00:52:46 +00:00
.service(routes::api::get_scope())
2024-03-27 21:19:07 +00:00
.service(actix_fs::Files::new("/static", "./static").index_file("index.html")) // static directory
.service(web::redirect("/favicon.ico", "/static/favicon.ico")) //? special redirect for favicon
2024-03-23 20:03:16 +00:00
})
.bind(bindip)?
2024-03-23 20:03:16 +00:00
.run()
.await?;
Ok(())
}