Read environment variables
Read values from FastEdge-defined environment variables in CDB Edge Compute programs.
Compute
Use this solution in your CDB Edge Compute service:
use fastedge::{
body::Body,
http::{Request, Response, StatusCode, Error},
};
use std::env;
#[fastedge::http]
fn main(_req: Request<Body>) -> Result<Response<Body>, Error> {
// get value of version
let version = match env::var("VERSION").ok() {
None => return Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::from("App misconfigured, missing mandatory parameter\n")),
Some(val) => val
};
let mut body: String = "".to_string();
body.push_str(&version);
// build response with body and custom header
Response::builder()
.status(StatusCode::OK)
.body(Body::from(body))
}