2024-06-24 22:46:04 +02:00
|
|
|
|
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
2024-07-27 22:15:30 +02:00
|
|
|
|
use actix_web::HttpServer;
|
2024-07-24 11:45:06 +02:00
|
|
|
|
use clap::Parser;
|
2024-07-27 22:15:30 +02:00
|
|
|
|
use log::info;
|
2024-07-14 18:31:08 +02:00
|
|
|
|
|
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();
|
|
|
|
|
|
2024-07-27 22:15:30 +02:00
|
|
|
|
// This can’t 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
|
|
|
|
|
2024-07-11 17:25:01 +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
|
|
|
|
|
2024-07-14 18:31:08 +02:00
|
|
|
|
info!("Starting on {address}:{port}");
|
2024-06-24 22:46:04 +02:00
|
|
|
|
|
2024-07-27 22:15:30 +02:00
|
|
|
|
HttpServer::new(move || li7y::app(&config, &pool))
|
|
|
|
|
.bind((address, port))?
|
|
|
|
|
.run()
|
|
|
|
|
.await
|
2024-06-24 22:46:04 +02:00
|
|
|
|
}
|