From 16f8cf5ced3ddcbfb142665e3f372e0fc8be73c5 Mon Sep 17 00:00:00 2001 From: ozpv <39195175+ozpv@users.noreply.github.com> Date: Tue, 26 May 2026 01:06:55 -0500 Subject: add site --- .gitattributes | 1 + .gitignore | 2 ++ Cargo.toml | 14 +++++++++ public/index.html | 4 +++ public/music.html | 4 +++ src/env.rs | 20 ++++++++++++ src/lib.rs | 2 ++ src/main.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/state.rs | 18 +++++++++++ 9 files changed, 156 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 public/index.html create mode 100644 public/music.html create mode 100644 src/env.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs create mode 100644 src/state.rs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5c1c87e --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* linguist-language=HolyC diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e875dbc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "site" +version = "0.1.0" +edition = "2024" + +[dependencies] +axum = "0.8.9" +serde = "1.0.228" +serde_json = "1.0.150" +tokio = { version = "1.52.3", features = ["macros", "rt-multi-thread"] } +tower = "0.5.3" +tower-http = { version = "0.6.11", features = ["compression-gzip", "fs", "timeout", "trace"] } +tracing = "0.1.44" +tracing-subscriber = "0.3.23" diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..524959f --- /dev/null +++ b/public/index.html @@ -0,0 +1,4 @@ + + +
Hello and welcome
+ diff --git a/public/music.html b/public/music.html new file mode 100644 index 0000000..22ba402 --- /dev/null +++ b/public/music.html @@ -0,0 +1,4 @@ + + +This is my music
+ diff --git a/src/env.rs b/src/env.rs new file mode 100644 index 0000000..0a4d46c --- /dev/null +++ b/src/env.rs @@ -0,0 +1,20 @@ +use std::{env, path::PathBuf}; + +pub struct Env { + pub site_addr: String, + pub dist_dir: PathBuf, +} + +impl Env { + pub fn get_or_default() -> Self { + let site_addr = env::var("SITE_ADDR").unwrap_or_else(|_| "127.0.0.1:3000".to_string()); + let dist_dir = env::var("DIST_DIR") + .unwrap_or_else(|_| format!("{}/public", env!("CARGO_MANIFEST_DIR"))) + .into(); + + Self { + site_addr, + dist_dir, + } + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c112ba4 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +pub mod env; +pub mod state; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1ddddfb --- /dev/null +++ b/src/main.rs @@ -0,0 +1,91 @@ +use axum::{ + Router, + extract::{Request, State}, + handler::HandlerWithoutStateExt, + http::StatusCode, + response::{Html, IntoResponse}, + routing::{get, get_service}, +}; +use site::{env::Env, state::AppState}; +use std::{path::PathBuf, time::Duration}; +use tokio::net::TcpListener; +use tower::util::ServiceExt; +use tower_http::{ + compression::CompressionLayer, + services::{ServeDir, ServeFile}, + timeout::TimeoutLayer, + trace::TraceLayer, +}; + +const ERR: (StatusCode, Html<&'static str>) = + (StatusCode::NOT_FOUND, Html("