Compare commits

..

2 Commits
0.1.2 ... main

Author SHA1 Message Date
Jan-Bulthuis
e6cc71fa47 feat: Set Cache-Control header on responses 2026-04-04 14:39:48 +02:00
Jan-Bulthuis
bbb19754bd fix: Use correct assets path 2026-04-02 19:26:49 +02:00
4 changed files with 19 additions and 12 deletions

2
Cargo.lock generated
View File

@ -1367,7 +1367,7 @@ dependencies = [
[[package]]
name = "karnaugh"
version = "0.1.2"
version = "0.1.4"
dependencies = [
"axum",
"clap",

View File

@ -1,6 +1,6 @@
[package]
name = "karnaugh"
version = "0.1.2"
version = "0.1.4"
edition = "2024"
[dependencies]
@ -10,7 +10,7 @@ itertools = "0.14.0"
tar = "0.4.44"
time = "0.3.47"
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.6.8", features = ["compression-br", "fs", "trace"] }
tower-http = { version = "0.6.8", features = ["compression-br", "fs", "trace", "set-header"] }
tracing = "0.1.43"
tracing-subscriber = "0.3.22"
typst-html = { git = "https://github.com/mkorje/typst.git", branch = "mathml" }

View File

@ -21,9 +21,9 @@
rec {
packages.karnaugh = pkgs.rustPlatform.buildRustPackage (final: {
pname = "karnaugh";
version = "0.1.2";
version = "0.1.4";
src = self;
cargoHash = "sha256-YRSK2Vk6I1y/PhH1ZyFAYF0E6IB55So3MTs8B5df4LM=";
cargoHash = "sha256-pwZOy+9cnpEskNf4HYC81UbXPJIOnUCtxEKzEVTrNyQ=";
});
packages.container = pkgs.dockerTools.buildImage {
name = "karnaugh";

View File

@ -8,7 +8,7 @@ use ::typst::syntax::VirtualPath;
use axum::{
Router,
extract::{Path, State},
http::StatusCode,
http::{HeaderValue, StatusCode, header::CACHE_CONTROL},
response::{Html, IntoResponse, Response},
routing::get,
};
@ -17,6 +17,7 @@ use itertools::Itertools;
use tower_http::{
compression::CompressionLayer,
services::{ServeDir, ServeFile},
set_header::SetResponseHeaderLayer,
trace::TraceLayer,
};
use tracing::{Level, info};
@ -97,14 +98,20 @@ async fn main() {
let mut favicon = state.config.get_full_assets_path();
favicon.push(PathBuf::from("favicon.svg"));
let assets_service = ServeDir::new(state.config.get_full_assets_path());
let app = Router::new()
.route("/", get(root_handler))
.route("/{*path}", get(typst_handler))
.route_service("/favicon.ico", ServeFile::new(favicon))
.nest_service("/assets", ServeDir::new(&state.config.assets_root))
.nest_service("/assets", assets_service)
.with_state(state.clone())
.layer(TraceLayer::new_for_http())
.layer(CompressionLayer::new());
.layer(CompressionLayer::new())
.layer(SetResponseHeaderLayer::overriding(
CACHE_CONTROL,
HeaderValue::from_static("public, max-age=86400, immutable"),
));
let socket = SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), state.config.port);
info!("Serving Karnaugh on socket {}", socket);