1- use askama:: Template ;
21use async_graphql:: { EmptyMutation , EmptySubscription , Schema } ;
32use axum:: http:: StatusCode ;
43use 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
11197async fn graphql_get_warning ( ) -> impl IntoResponse {
0 commit comments