Options and depend setup

This commit is contained in:
Evie Viau-Chow-Stuart 2023-03-21 08:55:55 -07:00
parent 984c45fbcf
commit 0f04eed0c9
Signed by: evie
GPG key ID: 928652CDFCEC8099
4 changed files with 2798 additions and 2 deletions

2713
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,3 +6,30 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
## Core
tokio = { version = "^1.26", features = ["full"] }
## Web
axum = { version = "^0.6", features = ["ws"] }
askama = { version = "0.12.0", features = ["with-axum"] }
askama_axum = "0.3.0"
## Database
sea-orm = { version = "^0.11", features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] }
sea-orm-migration = "0.11.1"
## Auth
rand = { version = "0.8.5", features = ["std_rng"] }
blake3 = "1.3.3"
argon2 = "0.5.0"
zxcvbn = "2.2.1"
## Data
serde = { version = "1.0.156", features = ["derive"] }
serde_derive = { version = "1.0.156" }
## Misc
tracing = "0.1.37"
tracing-subscriber = "0.3.16"

View file

@ -1,3 +1,37 @@
fn main() {
println!("Hello, world!");
mod options;
use std::net::SocketAddr;
use axum::Router;
use tracing::info;
use crate::options::{Opt, Options};
const VERSION: &str = env!("CARGO_PKG_VERSION");
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let options = Options::get();
info!("Starting CorrugatedCardboard v{}", VERSION);
info!("\tInstance Name: {}", options.name);
info!("\tListen Address: {}", options.listen_addr);
info!("\tRegistrations Enabled: {}", options.registration);
info!("Connecting to database & checking for migrations");
info!("Starting server");
// Axum setup
let app = Router::new();
let addr: SocketAddr = options.listen_addr
.parse()
.expect("Unable to parse listen address!");
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.expect("Failed to start the server!");
}

22
src/options.rs Normal file
View file

@ -0,0 +1,22 @@
use std::env;
// TODO: Make this better lol
pub struct Options {
pub name: String,
pub listen_addr: String,
pub database_url: String,
pub registration: bool
}
pub trait Opt {
fn get() -> Options;
}
impl Opt for Options {
fn get() -> Options {
Options {
name: env::var("NAME").unwrap_or_else(|_| "CorrugatedCardboard".to_string()),
listen_addr: env::var("HTTP_LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0:3926".to_string()),
database_url: env::var("DATABASE_URL").expect("DATABASE_URL is required!"),
registration: env::var("REGISTRATION").unwrap_or_else(|_| "false".to_string()).parse().unwrap()
}
}
}