2023-02-09 11:42:39 +01:00
|
|
|
use actix_files::Files;
|
2023-02-16 21:59:04 +01:00
|
|
|
use actix_web::{middleware::DefaultHeaders, web, App, HttpServer};
|
2023-04-09 17:59:18 +02:00
|
|
|
use std::env;
|
2023-04-09 16:58:21 +02:00
|
|
|
use std::io;
|
2023-02-09 00:08:31 +01:00
|
|
|
|
2023-02-08 20:49:05 +01:00
|
|
|
mod config;
|
2023-02-09 11:19:53 +01:00
|
|
|
mod template;
|
2023-02-08 20:49:05 +01:00
|
|
|
|
2023-02-09 10:59:06 +01:00
|
|
|
#[path = "routes/agreements.rs"]
|
|
|
|
mod agreements;
|
2023-02-08 20:49:05 +01:00
|
|
|
|
2023-02-08 22:27:40 +01:00
|
|
|
#[path = "routes/not_found.rs"]
|
|
|
|
mod not_found;
|
|
|
|
|
2023-02-09 10:59:06 +01:00
|
|
|
#[path = "routes/index.rs"]
|
|
|
|
mod index;
|
|
|
|
|
|
|
|
#[path = "routes/networks.rs"]
|
|
|
|
mod networks;
|
|
|
|
|
|
|
|
#[path = "routes/portfolio.rs"]
|
|
|
|
mod portfolio;
|
2023-02-08 22:14:57 +01:00
|
|
|
|
2023-02-20 15:14:08 +01:00
|
|
|
#[path = "routes/contrib.rs"]
|
|
|
|
mod contrib;
|
|
|
|
|
2023-02-08 20:49:05 +01:00
|
|
|
#[actix_web::main]
|
2023-02-09 00:08:31 +01:00
|
|
|
async fn main() -> io::Result<()> {
|
2023-02-09 11:42:39 +01:00
|
|
|
let config = config::get_config("./config/config.toml");
|
2023-02-08 20:49:05 +01:00
|
|
|
|
2023-04-09 15:19:23 +02:00
|
|
|
let addr = ("0.0.0.0", config.fc.port.unwrap());
|
2023-02-09 11:36:22 +01:00
|
|
|
|
2023-04-09 17:59:18 +02:00
|
|
|
let mut http = true;
|
|
|
|
let mut args = env::args();
|
|
|
|
args.next();
|
|
|
|
for argument in args {
|
|
|
|
if argument == "--no-http" {
|
|
|
|
http = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if http {
|
|
|
|
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
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-02-02 11:06:27 +01:00
|
|
|
}
|