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-28 00:17:44 +00:00
|
|
|
use std::sync::Mutex;
|
|
|
|
|
2024-03-30 00:52:46 +00:00
|
|
|
use actix_web::{web, App, HttpServer, Route};
|
2024-03-23 20:19:00 +00:00
|
|
|
use actix_files as actix_fs;
|
2024-03-23 19:35:31 +00:00
|
|
|
|
2024-03-25 21:26:56 +00:00
|
|
|
use crate::{config::definition::Config, database::Database};
|
2024-03-23 20:29:28 +00:00
|
|
|
|
2024-03-25 21:26:56 +00:00
|
|
|
pub(crate) async fn start_actix(config: &Config, database: Database) -> anyhow::Result<()> {
|
2024-03-23 21:44:50 +00:00
|
|
|
let bindip = format!("{}:{}", config.webserver.host, config.webserver.port);
|
2024-03-23 20:29:28 +00:00
|
|
|
|
|
|
|
log::info!("Serving an http server at http://{bindip}");
|
2024-03-25 21:26:56 +00:00
|
|
|
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
|
|
|
})
|
2024-03-23 19:35:31 +00:00
|
|
|
|
2024-03-23 20:29:28 +00:00
|
|
|
.bind(bindip)?
|
2024-03-23 20:03:16 +00:00
|
|
|
.run()
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|