Skip to content

Commit 4599a02

Browse files
committed
Remove dependency on askama
Bit of an overkill for two urls
1 parent 2948665 commit 4599a02

4 files changed

Lines changed: 11 additions & 78 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ clap = { version = "4.5.48", features = ["derive"] }
2020
uuid = { version = "1.18.1", features = ["serde"] }
2121
tracing = "0.1.41"
2222
tracing-subscriber = "0.3.20"
23-
askama = "0.14.0"
2423

2524
[dev-dependencies]
2625
http-body-util = "0.1.3"

src/main.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use askama::Template;
21
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
32
use axum::http::StatusCode;
43
use axum::response::{Html, IntoResponse};
@@ -74,14 +73,7 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
7473
)
7574
.route("/asset/{run}/{stream}/{det}/{id}", get(download_handler))
7675
.with_state(client)
77-
.fallback((
78-
StatusCode::NOT_FOUND,
79-
Html(
80-
NotFound::from_public_address(public_address.clone())
81-
.render()
82-
.expect("Rendering to a string shouldn't fail"),
83-
),
84-
))
76+
.fallback((StatusCode::NOT_FOUND, not_found_page(&public_address)))
8577
.layer(Extension(schema));
8678

8779
let listener = tokio::net::TcpListener::bind(config.bind_address).await?;
@@ -92,20 +84,14 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
9284
.await?)
9385
}
9486

95-
#[derive(Template)]
96-
#[template(path = "404.html")]
97-
struct NotFound {
98-
graphql_address: Url,
99-
graphiql_address: Url,
100-
}
101-
102-
impl NotFound {
103-
fn from_public_address(add: Url) -> Self {
104-
Self {
105-
graphql_address: add.join("graphql").unwrap(),
106-
graphiql_address: add.join("graphiql").unwrap(),
107-
}
108-
}
87+
fn not_found_page(public_address: &Url) -> Html<String> {
88+
let graphql = public_address.join("graphql").unwrap();
89+
let graphiql = public_address.join("graphiql").unwrap();
90+
Html(format!(
91+
include_str!("../templates/404.html"),
92+
graphql_address = graphql,
93+
graphiql_address = graphiql
94+
))
10995
}
11096

11197
async fn graphql_get_warning() -> impl IntoResponse {

templates/404.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<h1>GraphQL interface to Tiled</h1>
88
<p>
99
Service is available at
10-
<a href="{{ graphql_address }}">/graphql</a>.
10+
<a href="{graphql_address}">/graphql</a>.
1111
Playground is available for testing at
12-
<a href="{{ graphiql_address }}">/graphiql</a>
12+
<a href="{graphiql_address}">/graphiql</a>
1313
</p>
1414
</body>
1515
</html>

0 commit comments

Comments
 (0)