vanikam/src/main.rs

66 lines
1.9 KiB
Rust
Raw Normal View History

2024-05-13 20:54:58 +05:30
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
2024-05-13 21:30:15 +05:30
use std::env;
use actix_identity::IdentityMiddleware;
use actix_session::{storage::CookieSessionStore, SessionMiddleware};
use actix_web::{cookie::Key, middleware, App, HttpServer};
use db::migrate::RunMigrations;
2024-05-13 20:54:58 +05:30
mod billing;
2024-05-13 21:30:15 +05:30
mod identity;
2024-05-13 20:54:58 +05:30
mod inventory;
mod ordering;
2024-05-13 21:30:15 +05:30
mod settings;
mod db;
mod utils;
2024-05-13 20:54:58 +05:30
2024-05-13 21:30:15 +05:30
#[actix_web::main]
async fn main() {
let settings = settings::Settings::new().unwrap();
if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", &settings.log);
}
{
// Settings::new() outputs logs, but since we are only setting up logger _after_ Settings is
// initialized, this dummy reinitialization will output logs.
settings::Settings::new().unwrap();
}
pretty_env_logger::init();
let db = db::sqlx_postgres::Postgres::init(&settings.database.url).await;
db.migrate().await;
let secret_key = Key::from(settings.server.cookie_secret.as_bytes());
let socket_addr = settings.server.get_ip();
log::info!("Starting server at: {} {}", socket_addr, settings.server.domain);
HttpServer::new(move || {
App::new()
.wrap(IdentityMiddleware::default())
.wrap(tracing_actix_web::TracingLogger::default())
.wrap(middleware::Compress::default())
.app_data(actix_web::web::Data::new(settings.clone()))
.wrap(SessionMiddleware::new(
CookieSessionStore::default(),
secret_key.clone(),
))
.wrap(
middleware::DefaultHeaders::new().add(("Permissions-Policy", "interest-cohort=()")),
)
// .configure(auth::adapter::load_adapters(db.pool.clone(), &settings))
.configure(utils::random_string::GenerateRandomString::inject())
})
.bind(&socket_addr)
.unwrap()
.run()
.await
.unwrap();
2024-05-13 20:54:58 +05:30
}
2024-05-13 21:30:15 +05:30