2022-07-16 14:16:54 +02:00
|
|
|
use actix_web::{
|
|
|
|
middleware::{self, Logger},
|
2023-06-23 10:17:13 +02:00
|
|
|
web::{self},
|
|
|
|
App, HttpServer,
|
2022-07-16 14:16:54 +02:00
|
|
|
};
|
2021-12-21 00:15:04 +01:00
|
|
|
use dotenv::dotenv;
|
2023-06-23 10:17:13 +02:00
|
|
|
use log::error;
|
2021-05-01 12:39:40 +02:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
2022-03-01 00:53:47 +01:00
|
|
|
mod api;
|
2021-05-02 12:32:03 +02:00
|
|
|
mod client;
|
2022-03-01 15:24:17 +01:00
|
|
|
mod config;
|
2023-06-23 10:17:13 +02:00
|
|
|
mod health;
|
2021-05-01 12:39:40 +02:00
|
|
|
mod note;
|
2021-12-20 17:42:16 +01:00
|
|
|
mod size;
|
2022-03-01 15:24:17 +01:00
|
|
|
mod status;
|
2021-05-02 12:32:03 +02:00
|
|
|
mod store;
|
2021-05-01 12:39:40 +02:00
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2021-12-21 00:15:04 +01:00
|
|
|
dotenv().ok();
|
2022-10-07 21:28:25 +02:00
|
|
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or(config::VERBOSITY.as_str()));
|
|
|
|
|
2023-06-23 10:17:13 +02:00
|
|
|
if !store::can_reach_redis() {
|
|
|
|
error!("cannot reach redis");
|
|
|
|
panic!("canont reach redis");
|
|
|
|
}
|
|
|
|
|
2021-12-20 17:42:16 +01:00
|
|
|
return HttpServer::new(|| {
|
2021-05-01 12:39:40 +02:00
|
|
|
App::new()
|
2022-10-07 21:28:25 +02:00
|
|
|
.wrap(Logger::new("\"%r\" %s %b %T"))
|
2021-05-01 12:39:40 +02:00
|
|
|
.wrap(middleware::Compress::default())
|
|
|
|
.wrap(middleware::DefaultHeaders::default())
|
2021-12-20 17:42:16 +01:00
|
|
|
.configure(size::init)
|
2022-03-01 00:53:47 +01:00
|
|
|
.configure(api::init)
|
2021-05-02 12:32:03 +02:00
|
|
|
.configure(client::init)
|
2022-03-05 12:47:11 +01:00
|
|
|
.default_service(web::to(client::index))
|
2021-05-01 12:39:40 +02:00
|
|
|
})
|
2022-07-19 21:55:05 +02:00
|
|
|
.bind(config::LISTEN_ADDR.to_string())?
|
2021-05-01 12:39:40 +02:00
|
|
|
.run()
|
2021-12-20 17:42:16 +01:00
|
|
|
.await;
|
2021-05-01 12:39:40 +02:00
|
|
|
}
|