diff --git a/.devcontainer/compose.yml b/.devcontainer/compose.yml index ac5004d6..f6584ceb 100644 --- a/.devcontainer/compose.yml +++ b/.devcontainer/compose.yml @@ -10,7 +10,7 @@ services: - ..:/workspace:cached environment: DATABASE_URL: mariadb://stationapi:password@db-dc/stationapi - ACCEPT_HTTP1: true + DISABLE_GRPC_WEB: false HOST: 0.0.0.0 ports: - 50051:50051 diff --git a/.env b/.env index 61c7619c..bd445d34 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ ## API DATABASE_URL=mysql://root:password@localhost:3306/stationapi -ACCEPT_HTTP1=false +DISABLE_GRPC_WEB=false ## Migration MYSQL_USER= diff --git a/compose.prod.yml b/compose.prod.yml index 11fae245..fbaa38b9 100644 --- a/compose.prod.yml +++ b/compose.prod.yml @@ -10,7 +10,7 @@ services: - migration environment: DATABASE_URL: mysql://stationapi:password@db/stationapi - ACCEPT_HTTP1: true + DISABLE_GRPC_WEB: false HOST: 0.0.0.0 ports: - 50051:50051 diff --git a/compose.yml b/compose.yml index 2c1fe94a..716e99fd 100644 --- a/compose.yml +++ b/compose.yml @@ -5,15 +5,14 @@ services: build: context: . dockerfile: ./docker/api/Dockerfile.dev - command: cargo watch -s "cargo run -p stationapi" + command: bacon run -- --bin stationapi depends_on: - db volumes: - .:/app environment: DATABASE_URL: mariadb://stationapi:password@db/stationapi - ACCEPT_HTTP1: true - ENABLE_ALL_STATIONS_RPC: true + DISABLE_GRPC_WEB: false HOST: 0.0.0.0 ports: - 50051:50051 diff --git a/stationapi/src/main.rs b/stationapi/src/main.rs index bf3424eb..d06610c2 100644 --- a/stationapi/src/main.rs +++ b/stationapi/src/main.rs @@ -53,7 +53,7 @@ async fn run() -> std::result::Result<(), anyhow::Error> { tokio::spawn(station_api_service_status(health_reporter.clone())); - let accept_http1 = fetch_http1_flag(); + let disable_grpc_web = fetch_disable_grpc_web_flag(); let addr = fetch_addr()?; let db_url = fetch_database_url(); @@ -79,12 +79,20 @@ async fn run() -> std::result::Result<(), anyhow::Error> { info!("StationAPI Server listening on {}", addr); - Server::builder() - .accept_http1(accept_http1) - .add_service(tonic_web::enable(health_service)) - .add_service(tonic_web::enable(svc)) - .serve(addr) - .await?; + if disable_grpc_web == true { + Server::builder() + .add_service(health_service) + .add_service(svc) + .serve(addr) + .await?; + } else { + Server::builder() + .accept_http1(true) + .add_service(tonic_web::enable(health_service)) + .add_service(tonic_web::enable(svc)) + .serve(addr) + .await?; + } Ok(()) } @@ -120,13 +128,13 @@ fn fetch_database_url() -> String { Err(VarError::NotUnicode(_)) => panic!("$DATABASE_URL should be written in Unicode."), } } -fn fetch_http1_flag() -> bool { - match env::var("ACCEPT_HTTP1") { - Ok(s) => s.parse().expect("Failed to parse $ACCEPT_HTTP1"), +fn fetch_disable_grpc_web_flag() -> bool { + match env::var("DISABLE_GRPC_WEB") { + Ok(s) => s.parse().expect("Failed to parse $DISABLE_GRPC_WEB"), Err(env::VarError::NotPresent) => { - warn!("$ACCEPT_HTTP1 is not set. Falling back to false."); + warn!("$DISABLE_GRPC_WEB is not set. Falling back to false."); false } - Err(VarError::NotUnicode(_)) => panic!("$ACCEPT_HTTP1 should be written in Unicode."), + Err(VarError::NotUnicode(_)) => panic!("$DISABLE_GRPC_WEB should be written in Unicode."), } }