Skip to content

Commit 32e0e99

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 9cfe855 commit 32e0e99

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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>Numtracker</title>
5+
</head>
6+
<body>
7+
<h1>Data Acquisition File Naming Service</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)