mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
Listen on any IPv4 or any IPv6 address. (#428)
## Description Listening on `0.0.0.0` only binds to IPv4 addresses. We can listen on IPv4 and IPv6 by using `::`. I have opted to use the constants for this rather than parsing a string, both for clarity and to avoid errors. ## Changelog - Add a changelog entry (in the "Changelog entry" section below) if the changes in this PR have any user-facing impact. See [changelog guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide). - If no changelog is required ignore/remove this section and add a `no-changelog-required` label to the PR. ### Product _(Select all products this will be available in)_ - [x] community-edition - [ ] cloud <!-- product : end : DO NOT REMOVE --> ### Type <!-- See changelog structure: https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog --> _(Select only one. In case of multiple, choose the most appropriate)_ - [ ] highlight - [x] enhancement - [ ] bugfix - [ ] behaviour-change - [ ] performance-enhancement - [ ] security-fix <!-- type : end : DO NOT REMOVE --> ### Changelog entry <!-- - Add a user understandable changelog entry - Include all details needed to understand the change. Try including links to docs or issues if relevant - For Highlights start with a H4 heading (#### <entry title>) - Get the changelog entry reviewed by your team --> The v3 engine now binds to all IPv4 and IPv6 addresses. Previously it only used IPv4. <!-- changelog-entry : end : DO NOT REMOVE --> <!-- changelog : end : DO NOT REMOVE --> V3_GIT_ORIGIN_REV_ID: d63b5544bfbf2ad067113980fa61dd74213c7b78
This commit is contained in:
parent
79039afbc0
commit
8bee92864d
@ -1,4 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
use std::net;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -26,6 +27,8 @@ use hasura_authn_jwt::jwt;
|
||||
use hasura_authn_webhook::webhook;
|
||||
use lang_graphql as gql;
|
||||
|
||||
const DEFAULT_PORT: u16 = 3000;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version = VERSION)]
|
||||
struct ServerOptions {
|
||||
@ -36,7 +39,7 @@ struct ServerOptions {
|
||||
#[arg(long, value_name = "AUTHN_CONFIG_FILE", env = "AUTHN_CONFIG_PATH")]
|
||||
authn_config_path: PathBuf,
|
||||
#[arg(long, value_name = "SERVER_PORT", env = "PORT")]
|
||||
port: Option<i32>,
|
||||
port: Option<u16>,
|
||||
}
|
||||
|
||||
struct EngineState {
|
||||
@ -172,14 +175,16 @@ async fn start_engine(server: &ServerOptions) -> Result<(), StartupError> {
|
||||
.merge(explain_route)
|
||||
.merge(health_route);
|
||||
|
||||
let addr = format!("0.0.0.0:{}", server.port.unwrap_or(3000));
|
||||
|
||||
let log = format!("starting server on {addr}");
|
||||
// The "unspecified" IPv6 address will match any IPv4 or IPv6 address.
|
||||
let host = net::IpAddr::V6(net::Ipv6Addr::UNSPECIFIED);
|
||||
let port = server.port.unwrap_or(DEFAULT_PORT);
|
||||
let address = net::SocketAddr::new(host, port);
|
||||
let log = format!("starting server on {address}");
|
||||
println!("{log}");
|
||||
add_event_on_active_span(log);
|
||||
|
||||
// run it with hyper on `addr`
|
||||
axum::Server::bind(&addr.as_str().parse().unwrap())
|
||||
axum::Server::bind(&address)
|
||||
.serve(app.into_make_service())
|
||||
.with_graceful_shutdown(shutdown_signal())
|
||||
.await
|
||||
|
Loading…
Reference in New Issue
Block a user