Skip to content

Commit

Permalink
Merge pull request #26 from wasmCloud/ks2211/updates
Browse files Browse the repository at this point in the history
Update examples
  • Loading branch information
brooksmtownsend authored Dec 19, 2022
2 parents 44c14b7 + de97386 commit b241df0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
23 changes: 20 additions & 3 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This directory contains examples of using the `wasmcloud-js` library with sample

* NATS with WebSockets enabled

* There is sample infra via docker in the `test/infra` directory of this repo, `cd test/infra && docker-compose up`

* wasmCloud lattice (OTP Version)

* (OPTIONAL) Docker Registry with CORS configured
Expand All @@ -17,17 +19,32 @@ This directory contains examples of using the `wasmcloud-js` library with sample
## Build

```sh
$ npm install # this will run and build the rust deps
$ npm install webpack esbuild copy-webpack-plugin fs
$ #### if you want to use esbuild, follow these next 2 steps ####
$ node esbuild.js # this produces the esbuild version
$ mv out-esbuild.js out.js # rename the esbuild version
$ #### if you want to use webpack, follow the steps below ####
$ npx webpack --config=example-webpack.config.js # this produces the webpack output
$ mv out-webpack.js out.js #rename the webpack version to out.js
```

## Usage

1. Build the code
1. Build the code with esbuild or webpack

2. Rename the output file to `out.js`

2. Start a web server inside this directory (e.g `python3 -m http.server`)
3. Start a web server inside this directory (e.g `python3 -m http.server` or `npx serve`)

3. Navigate to a browser `localhost:<PORT>`

4. Open the developer console to view the host output
4. Open the developer console to view the host output

5. In the dev tools run `host` and you will get the full host object and methods

6. Start an actor with `host.launchActor('registry:5000/image', (data) => console.log(data))`. Echo actor is recommended (the 2nd parameter here is an invocation callback to handle the data from an invocation)

7. Link the actor with a provider running in Wasmcloud (eg `httpserver`)

8. Run a `curl localhost:port/echo` to see the response in the console (based off the invocation callback).
3 changes: 2 additions & 1 deletion examples/simple/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { startHost } from '../../dist/src'

(async () => {
console.log('USING A JS BUNDLER')
const host = await startHost('default', false, ['ws://localhost:4222'])
const host = await startHost('default', false, ['ws://localhost:6222'])
window.host = host;
console.log(host);
})()
3 changes: 2 additions & 1 deletion test/infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ services:
registry:
image: registry:2
ports:
- "5000:5000"
- "5001:5001"
volumes:
- ./docker-registry.yml:/etc/docker/registry/config.yml
nats:
image: nats:latest
ports:
- "4222:4222"
- "6222:6222"
volumes:
- ./nats.conf:/etc/nats.conf
command: "-c=/etc/nats.conf -js"
2 changes: 1 addition & 1 deletion test/infra/nats.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
listen: localhost:4222
websocket {
# host: "hostname"
port: 4222
port: 6222
no_tls: true
}

0 comments on commit b241df0

Please sign in to comment.