// SPDX-FileCopyrightText: 2024 Simon Bruder // // SPDX-License-Identifier: AGPL-3.0-or-later use std::env; use actix_web::{web, App, HttpServer}; use log::{debug, info}; #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); let pool: sqlx::PgPool = sqlx::Pool::::connect( &env::var("DATABASE_URL").expect("DATABASE_URL must be set"), ) .await .expect("failed to connect to database"); sqlx::migrate!() .run(&pool) .await .expect("failed to run migrations"); let address = env::var("LISTEN_ADDRESS").unwrap_or("::1".to_string()); let port = env::var("LISTEN_PORT").map_or(8080, |s| { s.parse::().expect("failed to parse LISTEN_PORT") }); let static_root = env::var("STATIC_ROOT").unwrap_or("static".to_string()); info!("Starting on {address}:{port} with static files from {static_root}"); debug!("Serving static files from {static_root}"); HttpServer::new(move || { App::new() .app_data(web::Data::new(pool.clone())) .service(web::scope("/api/v1").configure(li7y::api::v1::config)) .service(actix_files::Files::new("/static", &static_root)) .configure(li7y::frontend::config) }) .bind((address, port))? .run() .await }