diff --git a/Dockerfile b/Dockerfile index 450761a..48d0ffb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,15 +12,16 @@ RUN rustup target add x86_64-unknown-linux-musl && \ # This downloads and builds the dependencies early allowing built dependencies # to be cached. RUN mkdir src && echo 'fn main() {}' > src/main.rs -COPY Cargo.toml Cargo.lock ./ +COPY Cargo.toml Cargo.lock ./ -RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --release --target x86_64-unknown-linux-musl +RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --release --target x86_64-unknown-linux-musl -COPY static ./static -COPY src ./src +COPY ./static ./static +COPY ./src ./src +COPY ./templates ./templates RUN --mount=type=cache,target=/usr/local/cargo/registry < Result<(), Box> { .clone() .unwrap_or_else(|| Url::parse(&format!("http://{}", config.bind_address)).unwrap()); let schema = Schema::build(TiledQuery, EmptyMutation, EmptySubscription) - .data(RootAddress(public_address)) + .data(RootAddress(public_address.clone())) .data(client.clone()) .finish(); @@ -73,10 +73,7 @@ async fn serve(config: GlazedConfig) -> Result<(), Box> { ) .route("/asset/{run}/{stream}/{det}/{id}", get(download_handler)) .with_state(client) - .fallback(( - StatusCode::NOT_FOUND, - Html(include_str!("../static/404.html")), - )) + .fallback((StatusCode::NOT_FOUND, not_found_page(&public_address))) .layer(Extension(schema)); let listener = tokio::net::TcpListener::bind(config.bind_address).await?; @@ -87,6 +84,16 @@ async fn serve(config: GlazedConfig) -> Result<(), Box> { .await?) } +fn not_found_page(public_address: &Url) -> Html { + let graphql = public_address.join("graphql").unwrap(); + let graphiql = public_address.join("graphiql").unwrap(); + Html(format!( + include_str!("../templates/404.html"), + graphql_address = graphql, + graphiql_address = graphiql + )) +} + async fn graphql_get_warning() -> impl IntoResponse { ( StatusCode::METHOD_NOT_ALLOWED, diff --git a/static/404.html b/templates/404.html similarity index 70% rename from static/404.html rename to templates/404.html index 8361539..3ca1c06 100644 --- a/static/404.html +++ b/templates/404.html @@ -7,9 +7,9 @@

GraphQL interface to Tiled

Service is available at - /graphql. + /graphql. Playground is available for testing at - /graphiql + /graphiql