Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Torii external-url arg to support https #1898

Merged
merged 1 commit into from
Apr 28, 2024
Merged
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
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 @@
);

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
Loading