Skip to content

Commit

Permalink
Torii external-url arg to support https (#1898)
Browse files Browse the repository at this point in the history
  • Loading branch information
broody authored Apr 28, 2024
1 parent 6b6219f commit af9cdf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url>,

/// Enable Prometheus metrics.
Expand Down
12 changes: 11 additions & 1 deletion crates/torii/graphql/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down

0 comments on commit af9cdf6

Please sign in to comment.