Migrate to actix
This commit is contained in:
36
src/main.rs
36
src/main.rs
@ -1,31 +1,22 @@
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::fairing::AdHoc;
|
||||
use actix_web::{App, HttpServer, web, get};
|
||||
use clap::Parser;
|
||||
|
||||
use basic_oidc::constants::{DEFAULT_ADMIN_PASSWORD, DEFAULT_ADMIN_USERNAME};
|
||||
use basic_oidc::controllers::assets_controller::assets_route;
|
||||
use basic_oidc::data::app_config::AppConfig;
|
||||
use basic_oidc::data::entity_manager::EntityManager;
|
||||
use basic_oidc::data::user::{hash_password, User};
|
||||
use basic_oidc::controllers::assets_controller::assets_route;
|
||||
|
||||
#[get("/health")]
|
||||
fn index() -> &'static str {
|
||||
async fn health() -> &'static str {
|
||||
"Running"
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() -> Result<(), rocket::Error> {
|
||||
//env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let rocket = rocket::build()
|
||||
.mount("/", routes![index])
|
||||
.mount("/assets", routes![assets_route])
|
||||
.attach(AdHoc::config::<AppConfig>());
|
||||
let figment = rocket.figment();
|
||||
|
||||
// Initialize application
|
||||
let config: AppConfig = figment.extract().expect("config");
|
||||
let config: AppConfig = AppConfig::parse();
|
||||
|
||||
if !config.storage_path().exists() {
|
||||
log::error!(
|
||||
@ -55,5 +46,14 @@ async fn main() -> Result<(), rocket::Error> {
|
||||
.expect("Failed to create initial user!");
|
||||
}
|
||||
|
||||
rocket.launch().await
|
||||
log::info!("Server will listen on {}", config.listen_address);
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(health)
|
||||
.route("/assets/{path:.*}", web::get().to(assets_route))
|
||||
})
|
||||
.bind(config.listen_address)?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user