Rust and axum
Two axum binaries in one Cargo workspace, each started with run_script: { file: Cargo.toml, name: <bin> } on the workspace manifest. The web binary renders an askama page and calls the api binary over HTTPS with reqwest and native roots, which trust the devlanes CA through the SSL_CERT_FILE that the rust platform sets.
Requirements
Section titled “Requirements”- devlanes, with
devlanes setuprun once - Rust 1.88 or later
Run it
Section titled “Run it”cd languages-rust-axumdevlanes startdevlanes start --no-ui prints the start as text:
example-rust-axum@0 (main): 2/2 readyready web http://127.0.0.1:20641 https://example-rust-axum.localhostready api http://127.0.0.1:20640 https://api.example-rust-axum.localhostOpen https://example-rust-axum.localhost. The page says This is lane 0 of example-rust-axum., lists the lane values, then shows the answer of the api service with its status, the latency of the call and the SSL_CERT_FILE path.
The first start compiles the dependencies. If devlanes start stops waiting before that ends (after 180s by default), it prints ! timed out before every unit was ready and the build goes on; devlanes wait example-rust-axum@0 --timeout 10m waits for it.
During a start
Section titled “During a start”- devlanes runs
cargo run -p web --bin webandcargo run -p api --bin apiin this folder at the same time.run_scriptpoints at the workspaceCargo.toml, so devlanes looks up the member that owns each binary and adds-p. The file also makes the platformrust, so both getSSL_CERT_FILEpointing at~/.devlanes/ca/bundle.pem(system roots plus the devlanes CA) andCARGO_TERM_COLOR=always. - Both build into the same
target/, so one waits for the other’s build. Its log showsBlocking waiting for file lock on build directory, then compiles only its own crate. Theready.httpcheck on/healthzgives each 10 minutes. apilistens onHOSTandPORTand answers at https://api.example-rust-axum.localhost.webanswers at https://example-rust-axum.localhost.API_URLis${{ services.api.public_url }}, so each page load callshttps://api.example-rust-axum.localhost/api/itemsthrough the proxy. reqwest is built withrustls-tls-native-roots, which loads the certificates inSSL_CERT_FILEinstead of the system store, so the call works without turning certificate checks off.
Try next
Section titled “Try next”Change the stock of
Anvilincrates/api/src/items.rsfrom 12 to 11 and rundevlanes restart api. Cargo rebuilds only that crate (Finished ... in 1.08s) and the next page load shows"stock": 11. Nothing watches the files, sodevlanes restart webis howwebpicks up an edit.Load the page a few times, then run
devlanes logs web --tail 3. Each page load logs the api’s status and how long the call took:web#52 GET / called https://api.example-rust-axum.localhost/api/items: 200 in 8 msweb#53 GET / called https://api.example-rust-axum.localhost/api/items: 200 in 0 msweb#54 GET / called https://api.example-rust-axum.localhost/api/items: 200 in 0 msThe first call after a start includes the TLS handshake; later calls reuse the connection.
Point
SSL_CERT_FILEat a file with no certificates: create an emptyempty.pemand rundevlanes restart web --env SSL_CERT_FILE=empty.pem. The page now showsrequest failedandinvalid peer certificate: UnknownIssuer, even thoughdevlanes setupput the CA in the system store, because native roots read only that file.The restarted unit keeps the
--envvalue, so undo it withdevlanes stop webanddevlanes start web, then deleteempty.pem.Start a second lane:
git worktree add ../examples-checkout -b feat/checkout, thencd ../examples-checkout/languages-rust-axum && devlanes start. https://example-rust-axum1.localhost saysThis is lane 1 of example-rust-axum., with another port and lane colour, and its api call goes tohttps://api.example-rust-axum1.localhost. The worktree has its owntarget/, so its first start compiles everything again.Without a second worktree,
devlanes lane new --name example-rust-axum-review --startadds lane 1 in this folder. It shares thistarget/, so it starts without compiling (Finished ... in 0.15s).On Windows a running
.execannot be replaced, so while the review lane runsapi,devlanes restart apiin lane 0 after an edit fails withfailed to remove file ...\target\debug\api.exeandAccess is denied. (os error 5). Rundevlanes stop example-rust-axum-review:apifirst.devlanes lane clean 0 --yesstops lane 0 and deletes its data and logs. Run it with1for the second lane.
devlanes.yaml: thewebandapiservices, their hostnames and ready checks, andAPI_URL.Cargo.toml: the workspace and its pinned dependencies.crates/web/: the page.src/routes.rshas the handlers,src/api.rsthe HTTPS call toapi,templates/the askama pages.crates/api/: the JSON API.src/routes.rshas the handlers and CORS fromDEVLANES_ORIGINS,src/items.rsthe mock items.crates/shared/: the config read from the environment, the/lanevalues and theHOST/PORTlistener both binaries use.