RoadSign/src/main.rs

71 lines
1.8 KiB
Rust
Raw Normal View History

2024-01-13 04:35:59 +00:00
mod config;
mod proxies;
mod sideload;
2024-01-14 05:14:41 +00:00
use poem::{listener::TcpListener, EndpointExt, Route, Server};
2024-01-13 04:35:59 +00:00
use poem_openapi::OpenApiService;
2024-01-13 06:46:26 +00:00
use tracing::{error, info, Level};
2024-01-13 04:35:59 +00:00
use crate::proxies::route;
2024-01-13 04:35:59 +00:00
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
2024-01-13 06:46:26 +00:00
// Setting up logging
2024-01-13 04:35:59 +00:00
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "poem=debug");
}
2024-01-13 06:46:26 +00:00
tracing_subscriber::fmt()
.with_max_level(Level::DEBUG)
.init();
// Prepare all the stuff
let mut instance = proxies::Instance::new();
info!("Loading proxy regions...");
match proxies::loader::scan_regions(
config::C
.read()
.unwrap()
.get_string("regions")
.unwrap_or("./regions".to_string()),
) {
Err(_) => error!("Loading proxy regions... failed"),
Ok((regions, count)) => {
instance.regions = regions;
info!(count, "Loading proxy regions... done")
}
};
2024-01-13 04:35:59 +00:00
// Proxies
let proxies_server = Server::new(TcpListener::bind(
config::C
.read()
.unwrap()
.get_string("listen.proxies")
.unwrap_or("0.0.0.0:80".to_string()),
))
.run(route::handle.data(instance));
2024-01-13 04:35:59 +00:00
// Sideload
let sideload = OpenApiService::new(sideload::SideloadApi, "Sideload API", "1.0")
.server("http://localhost:3000/cgi");
let sideload_ui = sideload.swagger_ui();
2024-01-13 04:35:59 +00:00
let sideload_server = Server::new(TcpListener::bind(
2024-01-13 06:46:26 +00:00
config::C
.read()
.unwrap()
2024-01-13 04:35:59 +00:00
.get_string("listen.sideload")
.unwrap_or("0.0.0.0:81".to_string()),
))
.run(
Route::new()
.nest("/cgi", sideload)
.nest("/swagger", sideload_ui),
);
2024-01-13 04:35:59 +00:00
tokio::try_join!(proxies_server, sideload_server)?;
2024-01-13 04:35:59 +00:00
Ok(())
}