40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
use actix_web::{App, HttpServer, web::Data};
|
|
use dotenvy::dotenv;
|
|
use tracing::Level;
|
|
use tracing_subscriber::FmtSubscriber;
|
|
|
|
mod access;
|
|
mod config;
|
|
mod handlers;
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
let subscriber = FmtSubscriber::builder()
|
|
.with_max_level(Level::TRACE)
|
|
.finish();
|
|
|
|
tracing::subscriber::set_global_default(subscriber).expect("Could not initialize logging.");
|
|
|
|
dotenv().expect("Could not load .env file.");
|
|
|
|
let config = config::load_config();
|
|
|
|
let mut server = HttpServer::new({
|
|
let config = config.clone();
|
|
move || {
|
|
App::new()
|
|
.app_data(Data::new(config.clone()))
|
|
.wrap(actix_web::middleware::Logger::default())
|
|
.service(handlers::get_cache_item)
|
|
.service(handlers::put_cache_item)
|
|
}
|
|
})
|
|
.keep_alive(None); // disable HTTP keep-alive because it seems to break NX (at least in version 20.8)
|
|
|
|
for bind_address in config.bind_addresses.unwrap_or(vec!["::0".to_string()]) {
|
|
server = server
|
|
.bind((bind_address.clone(), 8080))
|
|
.expect(format!("Should have been able to bind to address {}", bind_address).as_str());
|
|
}
|
|
server.run().await
|
|
}
|