mylloon.fr/src/main.rs

59 lines
1.4 KiB
Rust

use actix_files::Files;
use actix_web::{middleware::DefaultHeaders, web, App, HttpServer};
mod config;
mod template;
#[path = "routes/agreements.rs"]
mod agreements;
#[path = "routes/not_found.rs"]
mod not_found;
#[path = "routes/index.rs"]
mod index;
#[path = "routes/networks.rs"]
mod networks;
#[path = "routes/portfolio.rs"]
mod portfolio;
#[path = "routes/contrib.rs"]
mod contrib;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let config = config::get_config("./config/config.toml");
let addr = ("0.0.0.0", config.fc.port.unwrap());
println!(
"Listening to {}://{}:{}",
config.clone().fc.scheme.unwrap(),
addr.0,
addr.1
);
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(config.clone()))
.wrap(DefaultHeaders::new().add((
"Onion-Location",
config.fc.onion.as_deref().unwrap_or_default(),
)))
.service(index::page)
.service(agreements::security)
.service(agreements::humans)
.service(agreements::robots)
.service(agreements::sitemap)
.service(networks::page)
.service(portfolio::page)
.service(contrib::page)
.service(Files::new("/", config.static_location.clone()))
.default_service(web::to(not_found::page))
})
.bind(addr)?
.run()
.await
}