Skip to content

Commit 4ef0c0f

Browse files
committed
Add fallback handler for unknown endpoints
Replaces the default browser 404 page stopping the root of the service looking the same as the server not running error state.
1 parent 8ef178d commit 4ef0c0f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN rustup target add x86_64-unknown-linux-musl && \
88

99
COPY ./Cargo.toml ./Cargo.toml
1010
COPY ./Cargo.lock ./Cargo.lock
11+
COPY ./static ./static
1112
COPY ./src ./src
1213

1314
RUN cargo build --release --target x86_64-unknown-linux-musl

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::error;
22

33
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
4+
use axum::http::StatusCode;
5+
use axum::response::Html;
46
use axum::routing::{get, post};
57
use axum::{Extension, Router};
68

@@ -54,6 +56,10 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn error::Error>> {
5456
let app = Router::new()
5557
.route("/graphql", post(graphql_handler))
5658
.route("/graphiql", get(graphiql_handler))
59+
.fallback((
60+
StatusCode::NOT_FOUND,
61+
Html(include_str!("../static/404.html")),
62+
))
5763
.layer(Extension(schema));
5864

5965
let listener = tokio::net::TcpListener::bind(config.bind_address).await?;

static/404.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Glazed</title>
5+
</head>
6+
<body>
7+
<h1>GraphQL interface to Tiled</h1>
8+
<p>
9+
Service is available at
10+
<a href="/graphql">/graphql</a>.
11+
Playground is available for testing at
12+
<a href="/graphiql">/graphiql</a>
13+
</p>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)