li7y/src/main.rs
Simon Bruder b22588cd0d
All checks were successful
/ build (push) Successful in 1m55s
Move app creation to lib.rs
This makes integration testing much easier as it can reuse the app
instance.
2024-07-27 22:15:58 +02:00

37 lines
968 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use actix_web::HttpServer;
use clap::Parser;
use log::info;
use li7y::Config;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let config = Config::parse();
// This cant be included in app, because app gets called in a (non-async) closure
let pool = sqlx::Pool::<sqlx::postgres::Postgres>::connect(&config.database_url)
.await
.expect("failed to connect to database");
sqlx::migrate!()
.run(&pool)
.await
.expect("failed to run migrations");
let address = config.listen_address;
let port = config.listen_port;
info!("Starting on {address}:{port}");
HttpServer::new(move || li7y::app(&config, &pool))
.bind((address, port))?
.run()
.await
}