Skip to content

Commit

Permalink
Torii external-url arg to support https
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Apr 27, 2024
1 parent 6b6219f commit f0866a9
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");

Check warning on line 53 in crates/torii/graphql/src/server.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/server.rs#L52-L53

Added lines #L52 - L53 were not covered by tests

let websocket_scheme = match websocket_url.scheme() {
"http" => "ws",
"https" => "wss",
_ => panic!("Invalid URL scheme") // URL validated on input so this never hits

Check warning on line 58 in crates/torii/graphql/src/server.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/server.rs#L55-L58

Added lines #L55 - L58 were not covered by tests
};

let _ = websocket_url.set_scheme(websocket_scheme);
websocket_url.to_string()

Check warning on line 62 in crates/torii/graphql/src/server.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/server.rs#L61-L62

Added lines #L61 - L62 were not covered by tests
} else {
"/graphql/ws".to_string()
};
Expand Down

0 comments on commit f0866a9

Please sign in to comment.