1+ use askama:: Template ;
12use async_graphql:: { EmptyMutation , EmptySubscription , Schema } ;
23use axum:: http:: StatusCode ;
34use axum:: response:: { Html , IntoResponse } ;
@@ -56,7 +57,7 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
5657 . clone ( )
5758 . unwrap_or_else ( || Url :: parse ( & format ! ( "http://{}" , config. bind_address) ) . unwrap ( ) ) ;
5859 let schema = Schema :: build ( TiledQuery , EmptyMutation , EmptySubscription )
59- . data ( RootAddress ( public_address) )
60+ . data ( RootAddress ( public_address. clone ( ) ) )
6061 . data ( client. clone ( ) )
6162 . finish ( ) ;
6263
@@ -75,7 +76,11 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
7576 . with_state ( client)
7677 . fallback ( (
7778 StatusCode :: NOT_FOUND ,
78- Html ( include_str ! ( "../static/404.html" ) ) ,
79+ Html (
80+ NotFound :: from_public_address ( public_address. clone ( ) )
81+ . render ( )
82+ . expect ( "Rendering to a string shouldn't fail" ) ,
83+ ) ,
7984 ) )
8085 . layer ( Extension ( schema) ) ;
8186
@@ -87,6 +92,22 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
8792 . await ?)
8893}
8994
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+ }
109+ }
110+
90111async fn graphql_get_warning ( ) -> impl IntoResponse {
91112 (
92113 StatusCode :: METHOD_NOT_ALLOWED ,
0 commit comments