70 lines
2.1 KiB
Rust
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();
|
|
}
|