You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oab/src/main.rs

62 lines
1.7 KiB
Rust

//
// main.rs
// Copyright (C) 2022 veypi <i@veypi.com>
// 2022-07-07 23:51
// Distributed under terms of the Apache license.
//
3 years ago
use actix_web::{
middleware,
web::{self, Data},
App, HttpServer,
};
3 years ago
use oab::{api, init_log, models, Clis, Result, CLI, CONFIG};
3 years ago
use tracing::{info, warn};
3 years ago
#[tokio::main]
async fn main() -> Result<()> {
init_log();
if let Some(c) = &CLI.command {
match c {
Clis::Init => {
models::init().await;
return Ok(());
}
_ => {}
};
};
web().await?;
Ok(())
}
async fn web() -> Result<()> {
std::env::set_var("RUST_LOG", "info");
std::env::set_var("RUST_BACKTRACE", "1");
let serv = HttpServer::new(move || {
let logger = middleware::Logger::default();
3 years ago
let json_config = web::JsonConfig::default()
.limit(4096)
3 years ago
.error_handler(|err, _req| {
3 years ago
// create custom error response
// oab::Error::InternalServerError
warn!("{:#?}", err);
actix_web::error::InternalError::from_response(
err,
actix_web::HttpResponse::Conflict().finish(),
)
.into()
});
let app = App::new();
app.wrap(logger)
.wrap(middleware::Compress::default())
3 years ago
.service(
web::scope("api")
.app_data(json_config)
3 years ago
.app_data(Data::new(CONFIG.db()))
3 years ago
.configure(api::routes),
)
});
info!("listen to {}", CONFIG.server_url);
serv.bind(CONFIG.server_url.clone())?.run().await?;
Ok(())
3 years ago
}