Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
set -e
set -e
# update timestamps to force a new build
touch src/main.rs
cargo build --release --locked --target x86_64-unknown-linux-musl
Expand Down
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
.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();

Expand All @@ -73,10 +73,7 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
)
.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?;
Expand All @@ -87,6 +84,16 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
.await?)
}

fn not_found_page(public_address: &Url) -> Html<String> {
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,
Expand Down
4 changes: 2 additions & 2 deletions static/404.html → templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<h1>GraphQL interface to Tiled</h1>
<p>
Service is available at
<a href="/graphql">/graphql</a>.
<a href="{graphql_address}">/graphql</a>.
Playground is available for testing at
<a href="/graphiql">/graphiql</a>
<a href="{graphiql_address}">/graphiql</a>
</p>
</body>
</html>
Loading