2023-08-16 22:24:29 +00:00
|
|
|
mod accounts;
|
2023-08-16 12:02:23 +00:00
|
|
|
mod api;
|
2023-08-16 17:27:22 +00:00
|
|
|
mod tokens;
|
2023-08-16 12:02:23 +00:00
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
use clap::Parser;
|
|
|
|
use log::info;
|
2023-08-16 16:05:54 +00:00
|
|
|
use sqlx::mysql::MySqlPool;
|
2023-08-16 12:02:23 +00:00
|
|
|
|
|
|
|
#[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");
|
|
|
|
|
2023-08-16 16:05:54 +00:00
|
|
|
let args = Args::parse();
|
|
|
|
|
2023-08-16 12:02:23 +00:00
|
|
|
let mut port: u16 = 8080;
|
|
|
|
if let Some(p) = args.port {
|
|
|
|
port = p;
|
|
|
|
}
|
|
|
|
|
2023-08-16 16:05:54 +00:00
|
|
|
let pool = MySqlPool::connect(&std::env::var("DATABASE_URL").map_err(|_| {
|
|
|
|
anyhow::Error::msg("Environment variable DATABASE_URL needs to be specified!")
|
|
|
|
})?)
|
|
|
|
.await?;
|
|
|
|
|
2023-08-16 22:24:29 +00:00
|
|
|
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!")
|
|
|
|
})?;
|
|
|
|
|
2023-08-16 16:05:54 +00:00
|
|
|
api::start(port, pool).await?;
|
2023-08-16 12:02:23 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|