2023-02-09 11:42:39 +01:00
|
|
|
use actix_files::Files;
|
2023-10-23 00:45:14 +02:00
|
|
|
use actix_web::{
|
|
|
|
middleware::{Compress, DefaultHeaders},
|
|
|
|
web, App, HttpServer,
|
|
|
|
};
|
2023-04-14 11:30:47 +02:00
|
|
|
use std::io::Result;
|
2024-11-26 13:23:16 +01:00
|
|
|
use utils::misc::is_debug;
|
2023-02-09 00:08:31 +01:00
|
|
|
|
2023-04-14 18:03:30 +02:00
|
|
|
use crate::routes::{
|
2023-10-15 20:58:20 +02:00
|
|
|
agreements, api_v1, blog, contact, contrib, cours, cv, gaming, index, memorial, not_found,
|
2023-08-16 10:58:41 +02:00
|
|
|
portfolio, setup, web3,
|
2023-04-14 18:03:30 +02:00
|
|
|
};
|
2023-04-14 11:44:49 +02:00
|
|
|
|
2023-02-08 20:49:05 +01:00
|
|
|
mod config;
|
2023-02-09 11:19:53 +01:00
|
|
|
mod template;
|
2023-02-20 15:14:08 +01:00
|
|
|
|
2023-04-14 11:44:49 +02:00
|
|
|
mod routes;
|
2024-11-14 17:34:15 +01:00
|
|
|
mod utils;
|
2023-04-14 11:30:58 +02:00
|
|
|
|
2023-02-08 20:49:05 +01:00
|
|
|
#[actix_web::main]
|
2023-04-14 11:30:47 +02:00
|
|
|
async fn main() -> Result<()> {
|
2024-05-28 20:26:58 +02:00
|
|
|
let config = config::get_configuration("./config/config.toml");
|
2023-02-08 20:49:05 +01:00
|
|
|
|
2024-11-26 13:23:16 +01:00
|
|
|
let addr = (
|
|
|
|
if is_debug() { "127.0.0.1" } else { "0.0.0.0" },
|
|
|
|
config.fc.port.unwrap(),
|
|
|
|
);
|
2023-02-09 11:36:22 +01:00
|
|
|
|
2023-04-09 18:23:46 +02:00
|
|
|
println!(
|
|
|
|
"Listening to {}://{}:{}",
|
2024-05-28 20:26:58 +02:00
|
|
|
config.clone().fc.scheme.unwrap(),
|
2023-04-09 18:23:46 +02:00
|
|
|
addr.0,
|
|
|
|
addr.1
|
|
|
|
);
|
|
|
|
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
2024-05-28 20:26:58 +02:00
|
|
|
.app_data(web::Data::new(config.clone()))
|
2023-10-23 00:45:14 +02:00
|
|
|
.wrap(Compress::default())
|
2023-10-15 20:58:20 +02:00
|
|
|
.wrap(
|
|
|
|
DefaultHeaders::new()
|
|
|
|
.add((
|
|
|
|
"Onion-Location",
|
|
|
|
config.fc.onion.as_deref().unwrap_or_default(),
|
|
|
|
))
|
|
|
|
.add(("Server", format!("ewp/{}", env!("CARGO_PKG_VERSION"))))
|
|
|
|
.add(("Permissions-Policy", "interest-cohort=()")),
|
|
|
|
)
|
2024-08-29 23:31:35 +02:00
|
|
|
.service(
|
2024-09-19 15:50:37 +02:00
|
|
|
web::scope("/api").service(
|
|
|
|
web::scope("v1")
|
|
|
|
.service(api_v1::love)
|
|
|
|
.service(api_v1::btf)
|
|
|
|
.service(api_v1::websites),
|
|
|
|
),
|
2024-08-29 23:31:35 +02:00
|
|
|
)
|
2023-04-09 18:23:46 +02:00
|
|
|
.service(index::page)
|
|
|
|
.service(agreements::security)
|
|
|
|
.service(agreements::humans)
|
|
|
|
.service(agreements::robots)
|
2024-01-25 17:46:00 +01:00
|
|
|
.service(agreements::webmanifest)
|
2023-04-14 11:30:58 +02:00
|
|
|
.service(blog::index)
|
2023-04-26 12:50:08 +02:00
|
|
|
.service(blog::rss)
|
2023-04-14 11:30:58 +02:00
|
|
|
.service(blog::page)
|
2023-08-16 10:52:53 +02:00
|
|
|
.service(contrib::page)
|
2023-04-16 13:18:15 +02:00
|
|
|
.service(cours::page)
|
2023-04-18 20:33:47 +02:00
|
|
|
.service(cv::page)
|
2023-08-16 10:52:53 +02:00
|
|
|
.service(gaming::page)
|
2023-08-16 10:58:41 +02:00
|
|
|
.service(memorial::page)
|
2023-10-21 20:53:47 +02:00
|
|
|
.configure(contact::pages)
|
2023-08-16 10:52:53 +02:00
|
|
|
.service(portfolio::page)
|
2023-08-16 10:51:58 +02:00
|
|
|
.service(setup::page)
|
2023-08-16 10:52:53 +02:00
|
|
|
.service(web3::page)
|
2024-05-28 20:26:58 +02:00
|
|
|
.service(Files::new("/", config.locations.static_dir.clone()))
|
2023-04-09 18:23:46 +02:00
|
|
|
.default_service(web::to(not_found::page))
|
|
|
|
})
|
|
|
|
.bind(addr)?
|
|
|
|
.run()
|
|
|
|
.await
|
2023-02-02 11:06:27 +01:00
|
|
|
}
|