From 2f6d760aa86bf6ceffcddf77cb4b34a78c90914d Mon Sep 17 00:00:00 2001 From: FunctionsAPI Date: Wed, 26 Mar 2025 11:55:52 +0000 Subject: [PATCH] Automatic push from FunctionsAPI --- Cargo.toml | 11 +++++++++++ README.md | 3 +-- src/main.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..940e1f5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] + edition = "2021" + name = "web" + version = "0.1.0" + +[dependencies] + openssl = { version = "0.10.35", features = ["vendored"] } + axum = "0.8" + pipeline-configuration = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git" } + serde_json = "1.0.138" + tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] } \ No newline at end of file diff --git a/README.md b/README.md index bc5f778..7f5c5a6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# 21df94dbf4e54a04afdd8add2268f03c - +# rust hello-world diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c109748 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,36 @@ +use axum::http::HeaderMap; +use axum::{routing::post, Router}; +use pipeline_configuration::pipeline_route::{PipelineRoute, Waypoint}; +use std::net::SocketAddr; +use tokio::net::TcpListener; + +async fn hello_world(headers: HeaderMap, body: String) -> String { + let env = std::env::vars().collect::>(); + let waypoints = vec![ + Waypoint { + latitude: 52.16975830941925, + longitude: -104.1288528141576, + measure: 0.0, + elevation: 540.0, + }, + Waypoint { + latitude: 52.20097892887157, + longitude: -104.0144102732867, + measure: 8563.471, + elevation: 540.0, + }, + ]; + let route = PipelineRoute::new(waypoints); + let start = route.location_of_measure(100.0).unwrap(); + format!("Request headers: {headers:?}, request body: {body}, env: {env:?}, start: {start:?}") +} + +#[tokio::main] +async fn main() { + let router = Router::new().route("/", post(hello_world)); + + let addr = SocketAddr::from(([0, 0, 0, 0], 8080)); + let tcp = TcpListener::bind(&addr).await.unwrap(); + println!("Ready and listening on {}", addr); + axum::serve(tcp, router).await.unwrap(); +}