50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
mod accounts;
|
|
mod api;
|
|
mod tokens;
|
|
|
|
use anyhow::Result;
|
|
use clap::Parser;
|
|
use log::info;
|
|
use sqlx::postgres::PgPool;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(author, version, about, long_about = None)]
|
|
struct Args {
|
|
/// Sets the port on which the API listens
|
|
#[arg(short, long)]
|
|
port: Option<u16>,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
|
|
|
info!("Starting NerdcultAPI v0.1");
|
|
|
|
let args = Args::parse();
|
|
|
|
let mut port: u16 = 8080;
|
|
if let Some(p) = args.port {
|
|
port = p;
|
|
}
|
|
|
|
let pool = PgPool::connect(&std::env::var("DATABASE_URL").map_err(|_| {
|
|
anyhow::Error::msg("Environment variable DATABASE_URL needs to be specified!")
|
|
})?)
|
|
.await?;
|
|
|
|
let _ = &std::env::var("SMTP_HOST_URL").map_err(|_| {
|
|
anyhow::Error::msg("Environment variable SMTP_HOST_URL needs to be specified!")
|
|
})?;
|
|
let _ = &std::env::var("SMTP_USER").map_err(|_| {
|
|
anyhow::Error::msg("Environment variable SMTP_HOST_URL needs to be specified!")
|
|
})?;
|
|
let _ = &std::env::var("SMTP_PASSWORD").map_err(|_| {
|
|
anyhow::Error::msg("Environment variable SMTP_HOST_URL needs to be specified!")
|
|
})?;
|
|
|
|
api::start(port, pool).await?;
|
|
|
|
Ok(())
|
|
}
|