Initial Axum server
This commit is contained in:
commit
1cd1b69676
7 changed files with 1271 additions and 0 deletions
56
src/main.rs
Normal file
56
src/main.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use axum::Router;
|
||||
use serde::Deserialize;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
fn default_port() -> u16 {
|
||||
8080
|
||||
}
|
||||
|
||||
fn default_address() -> String {
|
||||
"127.0.0.1".into()
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "UPPERCASE")]
|
||||
struct Settings {
|
||||
#[serde(default = "default_port")]
|
||||
port: u16,
|
||||
#[serde(default = "default_address")]
|
||||
address: String,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
fn new() -> color_eyre::Result<Self> {
|
||||
envious::Config::default()
|
||||
.with_prefix("MAIL_ADMIN_")
|
||||
.case_sensitive(true)
|
||||
.build_from_env()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> color_eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.with_target(true)
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.init();
|
||||
|
||||
let config = Settings::new()?;
|
||||
tracing::info!("Settings: {config:#?}");
|
||||
|
||||
let addr: SocketAddr = format!("{}:{}", config.address, config.port).parse()?;
|
||||
|
||||
tracing::info!("Listening on {addr}");
|
||||
|
||||
let router = Router::new();
|
||||
|
||||
Ok(axum::Server::bind(&addr)
|
||||
.serve(router.into_make_service())
|
||||
.await?)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue