From def715a044c866252594ee3af5b4092f9d2c97d3 Mon Sep 17 00:00:00 2001 From: HaQadosch Date: Sun, 19 Nov 2023 19:05:08 +0000 Subject: [PATCH] build and spin the app --- README.org | 90 +++++++++++++++++++++++++++++++++++++++++++++++ qstart/src/lib.rs | 2 +- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 426135b..ffe8528 100644 --- a/README.org +++ b/README.org @@ -144,4 +144,94 @@ The manifest file is =spin.toml= command = "cargo build --target wasm32-wasi --release" watch = ["src/**/*.rs", "Cargo.toml"] #+end_src +* Modifying the code +We change the =qstar/lib.rs= file to display the =hello world= message. +#+description: line change for message +#+name: lib.rs diff +#+begin_src shell + git diff +#+end_src +#+RESULTS: lib.rs diff +: diff --git a/qstart/src/lib.rs b/qstart/src/lib.rs +: index f3051ef..a51e027 100644 +: --- a/qstart/src/lib.rs +: +++ b/qstart/src/lib.rs +: @@ -8,5 +8,5 @@ fn handle_qstart(req: Request) -> anyhow::Result { +: Ok(http::Response::builder() +: .status(200) +: .header("content-type", "text/plain") +: - .body("Hello, Fermyon")?) +: + .body("Hello, World!")?) +: } +* Building the app +In the ~qstart/~ folder +#+begin_src shell + cd qstart/ + spin build +#+end_src + +#+RESULTS: +: Building component qstart with `cargo build --target wasm32-wasi --release` +: Finished release [optimized] target(s) in 0.17s +: Finished building all Spin components +* Running the app +We could have done ~spin build --up~ to autostart the app once the build has +been done. +#+description: running the app once build is finished +#+name: spin up the app +#+begin_src shell + cd qstart/ + spin up +#+end_src + +#+RESULTS: spin up the app +: Logging component stdio to ".spin/logs/" +: +: Serving http://127.0.0.1:3000 +: Available Routes: +: qstart: http://127.0.0.1:3000 (wildcard) +: 2023-11-19T18:38:54.648503Z ERROR spin_trigger::cli: Trigger executor failed +: Error: Unable to listen on 127.0.0.1:3000 +: +: Caused by: +: Address already in use (os error 98) + +In this case we have another app running in the same port. Let's see which one. +#+name: lsof +#+begin_src shell + lsof -i tcp:3000 +#+end_src + +#+RESULTS: lsof +: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME +: forgejo 1531870 haqadosch 7u IPv6 8599019 0t0 TCP *:3000 (LISTEN) + +So we kill that one and restart the ~spin up~. +#+name: spin up again +#+begin_src shell + kill -9 1531870 + cd qstart/ + spin up +#+end_src + +#+RESULTS: spin up again +: Logging component stdio to ".spin/logs/" +: +: Serving http://127.0.0.1:3000 +: Available Routes: +: qstart: http://127.0.0.1:3000 (wildcard) +* Try the app +We can display the page in your favourite browser or confirm with ~curl~ +#+name: curl +#+begin_src shell + curl -i localhost:3000 +#+end_src + +#+RESULTS: curl +: HTTP/1.1 200 OK +: content-type: text/plain +: transfer-encoding: chunked +: date: Sun, 19 Nov 2023 19:01:02 GMT +: +: Hello, World! diff --git a/qstart/src/lib.rs b/qstart/src/lib.rs index f3051ef..a51e027 100644 --- a/qstart/src/lib.rs +++ b/qstart/src/lib.rs @@ -8,5 +8,5 @@ fn handle_qstart(req: Request) -> anyhow::Result { Ok(http::Response::builder() .status(200) .header("content-type", "text/plain") - .body("Hello, Fermyon")?) + .body("Hello, World!")?) }