Skip to content

Commit 8383179

Browse files
authored
Merge pull request #58 from fermyon/fix-examples
Fix examples
2 parents 882a18d + 2865580 commit 8383179

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2305
-1566
lines changed

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ authors = ["Fermyon Engineering <[email protected]>"]
77
[lib]
88
crate-type = ["cdylib"]
99

10-
[package.metadata.component]
11-
package = "component:spin-fileserver-example"
12-
adapter = "adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm"
13-
1410
[dependencies]
1511
cargo-component-bindings = "0.4.0"
1612
# Helpful crate to manage errors.
-107 KB
Binary file not shown.

examples/javascript/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
http.wasm
3+
composed.wasm

examples/javascript/README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,18 @@ component for serving static files.
1111
- [Spin v2.0+](https://developer.fermyon.com/spin/install)
1212
- [Rust](https://rustup.rs/)
1313
- [cargo-component](https://github.com/bytecodealliance/cargo-component)
14-
- [wasm-tools](https://github.com/bytecodealliance/wasm-tools/)
15-
- Note that you'll need [this fork](https://github.com/dicej/wasm-tools/tree/wasm-compose-resource-imports) until [this PR](https://github.com/bytecodealliance/wasm-tools/pull/1261) has been merged and released.
14+
- [wac](https://github.com/bytecodealliance/wac)
1615
- [NodeJS](https://nodejs.org/en/download)
1716
- [componentize-js](https://github.com/dicej/componentize-js)
1817
- [curl](https://curl.se/download.html) or a web browser for testing
1918

2019
Once you have Rust and NodeJS installed, the following should give you everything else:
2120

22-
*NOTE*: Until https://github.com/bytecodealliance/componentize-js/pull/69 has
23-
been merged, you'll need to build and install `componentize-js` from source
24-
using
25-
https://github.com/dicej/componentize-js/tree/imported-resource-destructors
26-
instead of the `npm install` command below. See the README.md in that
27-
repository for instructions.
28-
2921
```shell
3022
rustup target add wasm32-wasi
3123
cargo install cargo-component
32-
cargo install --locked --git https://github.com/dicej/wasm-tools \
33-
--branch wasm-compose-resource-imports wasm-tools
34-
# See NOTE above for installing `componentize-js`
35-
# npm install @bytecodealliance/componentize-js
24+
cargo install wac-cli
25+
npm install -g @bytecodealliance/jco @bytecodealliance/componentize-js
3626
```
3727

3828
## Building and Running

examples/javascript/app.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { handle as spinFileserverHandle } from "wasi:http/[email protected]-rc-2023-10-18"
2-
import { OutgoingResponse, ResponseOutparam, OutgoingBody, Fields } from "wasi:http/[email protected]-rc-2023-10-18"
1+
import { handle as spinFileserverHandle } from "wasi:http/[email protected]"
2+
import { OutgoingResponse, ResponseOutparam, OutgoingBody, Fields } from "wasi:http/[email protected]"
33

44
const encoder = new TextEncoder()
55
const disposeSymbol = Symbol.dispose || Symbol.for('dispose')
@@ -10,14 +10,13 @@ function handle(request, responseOut) {
1010

1111
if (method.tag === "get") {
1212
if (path === "/hello") {
13-
const response = new OutgoingResponse(
14-
200,
15-
new Fields([["content-type", encoder.encode("text/plain")]])
16-
)
17-
13+
const fields = new Fields()
14+
fields.append("content-type", encoder.encode("text/plain"))
15+
const response = new OutgoingResponse(fields)
16+
1817
const responseBody = response.write()
1918
ResponseOutparam.set(responseOut, { tag: "ok", val: response })
20-
19+
2120
const responseStream = responseBody.write()
2221
responseStream.blockingWriteAndFlush(encoder.encode("Hello, world!"))
2322
responseStream[disposeSymbol]()
@@ -26,7 +25,8 @@ function handle(request, responseOut) {
2625
spinFileserverHandle(request, responseOut)
2726
}
2827
} else {
29-
const response = new OutgoingResponse(400, new Fields([]))
28+
const response = new OutgoingResponse(new Fields([]))
29+
response.setSatusCode(400)
3030
ResponseOutparam.set(responseOut, { tag: "ok", val: response })
3131
OutgoingBody.finish(response.write())
3232
}

examples/javascript/build.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { componentize } from "@bytecodealliance/componentize-js"
22
import { readFile, writeFile } from "node:fs/promises"
33

44
const { component } = await componentize(
5-
await readFile("app.mjs"),
5+
await readFile("app.mjs", "utf-8"),
66
{
77
witPath: "../wit",
88
worldName: "proxy",
9-
preview2Adapter: "../../adapters/fd1e948d/wasi_snapshot_preview1.reactor.wasm",
109
enableStdout: true,
1110
}
1211
);

examples/javascript/compose.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)