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-17 23:27:44 +05:30
|
|
|
mod db;
|
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;
|
2024-05-17 23:27:44 +05:30
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
2024-05-13 21:30:15 +05:30
|
|
|
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();
|
2024-05-17 23:27:44 +05:30
|
|
|
log::info!(
|
|
|
|
"Starting server at: {} {}",
|
|
|
|
socket_addr,
|
2024-05-18 19:40:48 +05:30
|
|
|
settings.server.hostname
|
2024-05-17 23:27:44 +05:30
|
|
|
);
|
2024-05-13 21:30:15 +05:30
|
|
|
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=()")),
|
|
|
|
)
|
2024-05-17 23:27:44 +05:30
|
|
|
// .configure(auth::adapter::load_adapters(db.pool.clone(), &settings))
|
2024-05-13 21:30:15 +05:30
|
|
|
.configure(utils::random_string::GenerateRandomString::inject())
|
2024-07-13 20:49:51 +05:30
|
|
|
.configure(utils::uuid::GenerateUUID::inject())
|
2024-05-13 21:30:15 +05:30
|
|
|
})
|
|
|
|
.bind(&socket_addr)
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-05-13 20:54:58 +05:30
|
|
|
}
|