From af9cdf67bc27f4720e9f945405f2e8a96d81de55 Mon Sep 17 00:00:00 2001 From: Yun Date: Sat, 27 Apr 2024 19:22:18 -1000 Subject: [PATCH] Torii external-url arg to support https (#1898) --- bin/torii/src/main.rs | 2 +- crates/torii/graphql/src/server.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index a14ff3d4c0..dc519b0451 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -93,7 +93,7 @@ struct Args { /// The external url of the server, used for configuring the GraphQL Playground in a hosted /// environment - #[arg(long)] + #[arg(long, value_parser = parse_url)] external_url: Option, /// Enable Prometheus metrics. diff --git a/crates/torii/graphql/src/server.rs b/crates/torii/graphql/src/server.rs index a6d81a35e4..4ac5f3dd78 100644 --- a/crates/torii/graphql/src/server.rs +++ b/crates/torii/graphql/src/server.rs @@ -49,7 +49,17 @@ fn graphql_filter( ); let subscription_endpoint = if let Some(external_url) = external_url { - format!("{external_url}/graphql/ws").replace("http", "ws") + let mut websocket_url = external_url.clone(); + websocket_url.set_path("/graphql/ws"); + + let websocket_scheme = match websocket_url.scheme() { + "http" => "ws", + "https" => "wss", + _ => panic!("Invalid URL scheme"), // URL validated on input so this never hits + }; + + let _ = websocket_url.set_scheme(websocket_scheme); + websocket_url.to_string() } else { "/graphql/ws".to_string() };