Skip to content

Commit

Permalink
Clean up fs access
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed Oct 4, 2023
1 parent 9c48f91 commit 41632f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
32 changes: 29 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ kuchiki = "0.8.1"
shuttle-axum = { version = "0.28.0" }
shuttle-runtime = { version = "0.28.0" }
once_cell = "1.17.1"
tower-http = { version = "0.4.4", features = ["fs"] }

23 changes: 4 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::path::PathBuf;

use axum::{
body::Body,
extract::TypedHeader,
headers::UserAgent,
http::{HeaderValue, StatusCode, Uri},
response::{self, Html, IntoResponse, Response},
routing::get,
Router,
};
use readable_readability::Readability;
use reqwest::header::{CONTENT_TYPE, USER_AGENT};
use tower_http::services::ServeDir;

mod utils;

Expand Down Expand Up @@ -161,24 +163,7 @@ pub fn static_content(
#[shuttle_runtime::main]
async fn axum() -> shuttle_axum::ShuttleAxum {
let router = Router::new()
.route(
"/static/Crimson.woff2",
get(|| async {
static_content(
include_bytes!("../static/fonts/Crimson.woff2",),
HeaderValue::from_static("text/woff2"),
)
}),
)
.route(
"/static/JetBrainsMono.woff2",
get(|| async {
static_content(
include_bytes!("../static/fonts/JetBrainsMono.woff2",),
HeaderValue::from_static("font/woff2"),
)
}),
)
.nest_service("/static", ServeDir::new(PathBuf::from("static")))
.fallback(readable);

Ok(router.into())
Expand Down
4 changes: 2 additions & 2 deletions static/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

@font-face {
font-family: "Crimson";
src: url(/static/Crimson.woff2);
src: url(/static/fonts/Crimson.woff2);
}

@font-face {
font-family: "JetBrainsMono";
src: url(/static/JetBrainsMono.woff2);
src: url(/static/fonts/JetBrainsMono.woff2);
}

* {
Expand Down

0 comments on commit 41632f7

Please sign in to comment.