aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/main.rs b/src/main.rs
index 648603b..34dafda 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,54 +12,54 @@ use warp::Filter;
#[derive(serde::Deserialize, Debug)]
#[serde(rename = "kebab-case")]
struct UserQuery {
- #[serde(default)]
- theme: Option<Arc<str>>,
- #[serde(flatten)]
- #[serde(default)]
- font: Option<FontQuery>,
- #[serde(flatten)]
- rest: BTreeMap<String, String>
+ #[serde(default)]
+ theme: Option<Arc<str>>,
+ #[serde(flatten)]
+ #[serde(default)]
+ font: Option<FontQuery>,
+ #[serde(flatten)]
+ rest: BTreeMap<String, String>
}
#[tokio::main]
async fn main() {
- env_logger::Builder::new()
- .filter_level(LevelFilter::Warn)
- .parse_filters(&var("LFME_LOG_LEVEL").unwrap_or_default())
- .target(
- var("LFME_LOG_FILE").ok()
- .map(
- |f| env_logger::Target::Pipe(
- Box::new(File::options()
- .append(true)
- .open(f)
- .expect("couldn't open LFME_LOG_FILE")))
- )
- .unwrap_or(env_logger::Target::Stderr)
- ).init();
+ env_logger::Builder::new()
+ .filter_level(LevelFilter::Warn)
+ .parse_filters(&var("LFME_LOG_LEVEL").unwrap_or_default())
+ .target(
+ var("LFME_LOG_FILE").ok()
+ .map(
+ |f| env_logger::Target::Pipe(
+ Box::new(File::options()
+ .append(true)
+ .open(f)
+ .expect("couldn't open LFME_LOG_FILE")))
+ )
+ .unwrap_or(env_logger::Target::Stderr)
+ ).init();
- std::sync::LazyLock::force(&STATE);
+ std::sync::LazyLock::force(&STATE);
- let user = warp::path!("user" / String)
- .and(warp::query::<UserQuery>())
- .then(|s, q: UserQuery| async move {
- log::debug!(target: "lfm::server::user", "Handling request for user `{s}` with {q:?}");
- let (ctx, dur) = STATE.get_userinfo(&s).await;
- let ResponseCtx(mut data, status) = ResponseCtx::create(ctx, q.font, q.rest).await;
-
- let theme = q.theme.filter(|a| STATE.handlebars().has_template(&a)).unwrap_or_else(|| STATE.default_theme());
- log::debug!(target: "lfm::server::user", "Using theme {theme}");
- warp::reply::with_header(
- warp::reply::with_header(
- warp::reply::with_status(
- warp::reply::html(
- STATE.handlebars().render(&theme, &data).unwrap()
- ), status
- ), "Refresh", dur.as_secs()
- ), "X-Selected-Theme", theme.as_ref()
- )
- });
+ let user = warp::path!("user" / String)
+ .and(warp::query::<UserQuery>())
+ .then(|s, q: UserQuery| async move {
+ log::debug!(target: "lfm::server::user", "Handling request for user `{s}` with {q:?}");
+ let (ctx, dur) = STATE.get_userinfo(&s).await;
+ let ResponseCtx(data, status) = ResponseCtx::create(ctx, q.font, q.rest).await;
- warp::serve(user)
- .bind(([127,0,0,1], STATE.port())).await;
+ let theme = q.theme.filter(|a| STATE.handlebars().has_template(&a)).unwrap_or_else(|| STATE.default_theme());
+ log::debug!(target: "lfm::server::user", "Using theme {theme}");
+ warp::reply::with_header(
+ warp::reply::with_header(
+ warp::reply::with_status(
+ warp::reply::html(
+ STATE.handlebars().render(&theme, &data).unwrap()
+ ), status
+ ), "Refresh", dur.as_secs()
+ ), "X-Selected-Theme", theme.as_ref()
+ )
+ });
+
+ warp::serve(user)
+ .bind(([127,0,0,1], STATE.port())).await;
}