li7y/src/main.rs

37 lines
968 B
Rust
Raw Normal View History

2024-06-24 22:46:04 +02:00
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use actix_web::HttpServer;
2024-07-24 11:45:06 +02:00
use clap::Parser;
use log::info;
2024-07-24 11:45:06 +02:00
use li7y::Config;
2024-06-24 22:46:04 +02:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
2024-07-13 11:33:46 +02:00
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
2024-06-24 22:46:04 +02:00
2024-07-24 11:45:06 +02:00
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)
2024-07-24 11:45:06 +02:00
.await
.expect("failed to connect to database");
2024-06-24 22:46:04 +02:00
sqlx::migrate!()
.run(&pool)
.await
.expect("failed to run migrations");
2024-06-24 22:46:04 +02:00
2024-07-24 11:45:06 +02:00
let address = config.listen_address;
let port = config.listen_port;
2024-06-24 22:46:04 +02:00
info!("Starting on {address}:{port}");
2024-06-24 22:46:04 +02:00
HttpServer::new(move || li7y::app(&config, &pool))
.bind((address, port))?
.run()
.await
2024-06-24 22:46:04 +02:00
}