vanikam/src/main.rs
Aravinth Manivannan 953d8d9fb7
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful
feat: include minor and major quantity description in Product and amend DB for same
closes: #54
2024-07-17 16:24:40 +05:30

70 lines
2.1 KiB
Rust

// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
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;
mod billing;
mod db;
mod identity;
mod inventory;
mod ordering;
mod settings;
#[cfg(test)]
mod tests;
mod types;
mod utils;
#[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.hostname
);
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())
.configure(utils::uuid::GenerateUUID::inject())
})
.bind(&socket_addr)
.unwrap()
.run()
.await
.unwrap();
}