URL path based routing for microservices

Send request to different origin servers based on the URL path.

VCL

Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):

Compute@Edge

Use this solution in your Compute@Edge service:

  1. Rust
match (req.get_path(), req.get_query_str()) {
// Requests for exactly / => origin 0
// (query strings not allowed)
("/", None) => Ok(req.send(BACKEND_ORIGIN_0)?),
// Requests for /status and all subpaths => origin 1
// (query strings allowed)
(s, _) if s == "/status" || s.starts_with("/status/") => Ok(req.send(BACKEND_ORIGIN_1)?),
// Unrecognised path => 404 error
_ => Ok(
Response::from_body("The page you requested could not be found")
.with_status(StatusCode::NOT_FOUND),
),
}