这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/containers.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 5
---

# Running in a container
Expand Down
11 changes: 5 additions & 6 deletions docs/docs/features/_category_.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"label": "Features",
"position": 4,
"link": {
"type": "generated-index"
}
"label": "Features",
"position": 2,
"link": {
"type": "generated-index"
}
}
4 changes: 2 additions & 2 deletions docs/docs/features/dynamic-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ After defining the route paremeters, the worker receives a special argument call

Check these guides to understand how to read parameters in the different supported languages:

* [Dynamic routes in JavaScript](../tutorials/javascript-workers.md#dynamic-routes)
* [Dynamic routes in Rust](../tutorials/rust-workers.md#dynamic-routes)
* [Dynamic routes in JavaScript](../languages/javascript.md#dynamic-routes)
* [Dynamic routes in Rust](../languages/rust.md#dynamic-routes)

## Dynamic routes and folders

Expand Down
8 changes: 4 additions & 4 deletions docs/docs/features/environment-variables.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
sidebar_position: 4
sidebar_position: 5
---

# Environment Variables
# Environment variables

Wasm Workers Server allows you to configure environment variables so a worker can read them. This configuration is done through the `TOML` file associated to a worker (a `TOML` file with the same filename as the worker). **This means every worker has its own set of environment variables**.

Expand All @@ -18,8 +18,8 @@ JSON_MESSAGE = "Hello 👋! This message comes from an environment variable"

Then, you can read them in your worker:

* [Read environment variables in a JavaScript worker](../tutorials/javascript-workers.md#read-environment-variables)
* [Read environment variables in a Rust worker](../tutorials/rust-workers.md#read-environment-variables)
* [Read environment variables in a JavaScript worker](../languages/javascript.md#read-environment-variables)
* [Read environment variables in a Rust worker](../languages/rust.md#read-environment-variables)

## Inject existing environment variables

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/features/key-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ For now, the data is only stored in memory and cleaned up on every restart.

## How it works?

The K/V store follows the same snapshot approach as [Requests / Responses](../how-it-works.md#how-it-works) data. On every request, the worker receives a snapshot of the K/V status for the configured namespace.
The K/V store follows the same snapshot approach as [Requests / Responses](../get-started/how-it-works.md#how-it-works) data. On every request, the worker receives a snapshot of the K/V status for the configured namespace.

The worker may access all the data and perform changes over it. Then, a new K/V status is returned and the internal status is overriden.

### Add a K/V to a worker

* [Add a K/V store to JavaScript workers](../tutorials/javascript-workers.md#add-a-key--value-store)
* [Add a K/V store to Rust workers](../tutorials/rust-workers.md#add-a-key--value-store)
* [Add a K/V store to JavaScript workers](../languages/javascript.md#add-a-key--value-store)
* [Add a K/V store to Rust workers](../languages/rust.md#add-a-key--value-store)

## Limitations

Expand Down
166 changes: 166 additions & 0 deletions docs/docs/features/multiple-language-runtimes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
sidebar_position: 2
---

# Multiple language runtimes

Wasm Workers Server allows you to extend the supported languages by adding new language runtimes. In other words, you can run workers based on languages like Python or Ruby.

## How it works?

To provide these language runtimes, `wws` relies on the [WebAssembly Language Runtimes](https://github.com/vmware-labs/webassembly-language-runtimes) project. It provides popular language runtimes precompiled to WebAssembly, like Ruby and Python. `wws` integrates with this repository and allows you to list, install and uninstall the different available languages:

```
wws runtimes --help

Usage: wws runtimes [OPTIONS] <COMMAND>

Commands:
install Install a new language runtime (like Ruby, Python, etc)
list List all available runtimes to install. By default, it uses the WebAssembly Language Runtime repository
check List of locally installed runtimes
uninstall Uninstall a language runtime
help Print this message or the help of the given subcommand(s)

Options:
--repo-url <REPO_URL> Set a different repository URL
--repo-name <REPO_NAME> Gives a name to the given repository URL
-h, --help Print help information
```

## The .wws.toml file

After installing a language runtime, `wws` creates a `.wws.toml` file in your project folder. This file saves the language runtime metadata. We recommend you to commit this file to your repository. It allows other developers to install the required language runtimes by running a single command:

```
wws runtimes install
```

## Manage language runtimes

### List available language runtimes

You can list the avilable runtimes with the `runtimes list` command:

```
wws runtimes list
⚙️ Fetching data from the repository...
┌────────┬─────────┬───────────┬─────────────┐
│ Name │ Version │ Extension │ Binary │
├────────┼─────────┼───────────┼─────────────┤
│ ruby │ 3.2.0 │ rb │ ruby.wasm │
├────────┼─────────┼───────────┼─────────────┤
│ python │ 3.11.1 │ py │ python.wasm │
└────────┴─────────┴───────────┴─────────────┘
```

The table provides the following data:

* **Name**: the name of the language runtime
* **Version**: a specific version for that language runtime. You can find multiple versions and variations
* **Extension**: the file extension associated to this language runtimes. For example, `wws` will load `*.rb` as workers if you install the `ruby` runtime
* **Binary**: the name of the Wasm module

### Install a new language runtime

To install a new language runtime, you need to provide the name and the version in the given repository:

```
wws runtimes install ruby 3.2.0
⚙️ Fetching data from the repository...
🚀 Installing the runtime...
✅ Done
```

The language runtime and required files will be installed in the `.wws` folder:

```
tree ./.wws
./.wws
└── runtimes
   └── wlr
   ├── python
   │   └── 3.11.1
   │   ├── poly.py
   │   ├── python.wasm
   │   └── template.txt
   └── ruby
   └── 3.2.0
   ├── poly.rb
   ├── ruby.wasm
   └── template.txt
```

#### Install the language runtimes for an existing project

If the project has a `.wws.toml` file, you can install quickly all the required language runtimes. You can run the `runtimes install` command without any extra parameter. `wws` will read the configuration file and install all missing runtimes:

```
./wws runtimes install
⚙️ Checking local configuration...
🚀 Installing: wlr - python / 3.11.1
🚀 Installing: wlr - ruby / 3.2.0
✅ Done
```

### Check installed language runtimes

You can check the installed language runtimes with the `runtimes check` command:

```
wws runtimes check
┌───────────┬────────┬─────────┬───────────┬─────────────┐
│ Installed │ Name │ Version │ Extension │ Binary │
├───────────┼────────┼─────────┼───────────┼─────────────┤
│ ✅ │ python │ 3.11.1 │ py │ python.wasm │
├───────────┼────────┼─────────┼───────────┼─────────────┤
│ ✅ │ ruby │ 3.2.0 │ rb │ ruby.wasm │
└───────────┴────────┴─────────┴───────────┴─────────────┘
```

If a runtime is present in the `.wws.toml` file but it's not installed in the system, the "Installed" field will show an error:

```
wws runtimes check
┌───────────┬────────┬─────────┬───────────┬─────────────┐
│ Installed │ Name │ Version │ Extension │ Binary │
├───────────┼────────┼─────────┼───────────┼─────────────┤
│ ❌ │ python │ 3.11.1 │ py │ python.wasm │
├───────────┼────────┼─────────┼───────────┼─────────────┤
│ ❌ │ ruby │ 3.2.0 │ rb │ ruby.wasm │
└───────────┴────────┴─────────┴───────────┴─────────────┘

💡 Tip: there are missing language runtimes. You can install them with `wws runtimes install`
```

We recommend you to check the 💡 tips as they provide very useful information

### Uninstall a language runtime

To uninstall a language runtime, use the `runtimes uninstall` command and provide the runtime name and version. You can get this information from the [`runtimes check command`](#check-installed-language-runtimes).

```
wws runtimes uninstall ruby 3.2.0
🗑 Uninstalling: wlr - ruby / 3.2.0
✅ Done
```

This command also edits the `.wws.toml` file to remove any reference to that specific runtime

## Configure a different repository

By default, `wws` relies on the binaries from the [WebAssembly Language Runtimes](https://github.com/vmware-labs/webassembly-language-runtimes) project. This project contains precompiled language runtimes for many popular languages. When you call the `list` or `install` commands, `wws` fetches the metadata from this project and continue processing your request.

If you want to set your own language runtimes repository, you can configure `wws` to fetch the metadata from a different place. For that, you can define the `WWS_REPO_NAME` and `WWS_REPO_URL` environment variables or use the `--repo-name` and `--repo-url` arguments:

```
# Via environment variables
export WWS_REPO_NAME=my-repo
export WWS_REPO_URL=https://example.com/index.toml

# Via arguments
wws runtimes list --repo-name=my-repo --repo-url=https://example.com/index.toml
wws runtimes install ruby 3.2.0 --repo-name=my-repo --repo-url=https://example.com/index.toml
```

After installing a language runtime, the repository information is also stored in the `.wws.toml` file. Developers that install the required language runtimes for an existing project will download them always from the right repository.
2 changes: 1 addition & 1 deletion docs/docs/features/static-assets.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 2
sidebar_position: 4
---

# Static assets
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/get-started/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "Wasm Workers Server",
"position": 1,
"collapsed": false,
"collapsible": false
}
File renamed without changes.
10 changes: 6 additions & 4 deletions docs/docs/intro.md → docs/docs/get-started/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
sidebar_position: 1
---

# What's Wasm Workers Server?
# Introduction

Wasm Workers Server is a project that allows you to run serverless code using a lightweight construct called "workers", explained later in the document. The server itself is implemented as a self-contained binary that routes HTTP requests to a WebAssembly runtime that hosts the workers. It looks for `.wasm` and other compatible modules (like JavaScript files) in the given folder and associate HTTP endpoints based on their path:
## What's Wasm Workers Server?

Wasm Workers Server is a framework that allows you to develop and run serverless applications using a lightweight construct called "workers", explained later in the document. The server itself is implemented as a self-contained binary that routes HTTP requests to a WebAssembly runtime that hosts the workers. It looks for `.wasm` and other compatible modules (like JavaScript files) in the given folder and associate HTTP endpoints based on their path:

```bash
$ wws --help
Expand All @@ -28,9 +30,9 @@ $ curl http://localhost:8080/api/hello
Hello Wasm!
```

That's all! Now it's your turn [to download and start using Wasm Workers Server](./start.md).
That's all! Now it's your turn [to download and start using Wasm Workers Server](./quickstart.md).

# What's a worker?
## What's a worker?

Worker has many definitions in the software ecosystem. In the context of the Web Platform, **a worker is a resource that listens to events and replies to them**. In our context, **a worker is a script or function that receives an HTTP request and returns an HTTP response**.

Expand Down
19 changes: 12 additions & 7 deletions docs/docs/start.md → docs/docs/get-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@
sidebar_position: 2
---

# Getting Started
# Quickstart

Wasm Workers runs almost anywhere. Thanks to its portability, downloading and running it anywhere is quite simple.

First, you need to install the `wws` server:
First, you need to install `wws`:

```bash
curl https://raw.githubusercontent.com/vmware-labs/wasm-workers-server/main/install.sh | bash
curl -fsSL https://workers.wasmlabs.dev/install | bash
```

Now, you can check the server:
Now, you can check the different commands and options:

```bash
wws --help

Usage: wws [OPTIONS] [PATH]
Usage: wws [OPTIONS] [PATH] [COMMAND]

Commands:
runtimes Manage the language runtimes in your project
help Print this message or the help of the given subcommand(s)

Arguments:
[PATH] Folder to read WebAssembly modules from [default: .]

Options:
--host <HOSTNAME> Hostname to initiate the server [default: 127.0.0.1]
-p, --port <PORT> Port to initiate the server [default: 8080]
--prefix <PREFIX> Prepend the given path to all URLs [default: ]
-h, --help Print help information
-V, --version Print version information
```
Expand Down Expand Up @@ -54,7 +59,7 @@ Now, open your browser at <http://127.0.0.1:8080>.

Now you got the taste of Wasm Workers, it's time to create your first worker:

* [Create your first JavaScript worker](./tutorials/javascript-workers.md)
* [Create your first Rust worker](./tutorials/rust-workers.md)
* [Create your first JavaScript worker](../languages/javascript.md)
* [Create your first Rust worker](../languages/rust.md)

And if you are curious, here you have a guide about [how it works](./how-it-works.md).
10 changes: 10 additions & 0 deletions docs/docs/languages/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"label": "Supported languages",
"position": 3,
"collapsed": false,
"collapsible": false,
"link": {
"type": "doc",
"id": "introduction"
}
}
45 changes: 45 additions & 0 deletions docs/docs/languages/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Introduction

Wasm Workers Server can run `.wasm` modules natively. When you run `wws` in a folder, any file with this extension will run as a worker:

```bash
wws

⚙️ Loading routes from: .
🗺 Detected routes:
- http://127.0.0.1:8080/
=> index.wasm (name: default)
🚀 Start serving requests at http://127.0.0.1:8080
```

However, these are not the only files `wws` can manage. You can extend `wws` with different language runtimes to run files from several languages like [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), [Ruby](https://www.ruby-lang.org) and [Python](https://www.python.org/).

## How are multiple language runtimes supported?

By default, `wws` only supports Wasm modules and JavaScript files. For any other language, you need the language interpreter or runtime. These runtimes are also Wasm modules. When you run `wws`, it loads the available runtimes and mount the source code from your workers.

However, compiling a language interpreter is not an easy task. To simplify this process, `wws` relies by default in the [WebAssembly Language Runtimes](https://github.com/vmware-labs/webassembly-language-runtimes). This projects offers a set of precompiled languages runtimes you can plug and play in projects like `wws`.

## How to manage language runtimes in wws?

You can check the available commands directly in the `wws` CLI:

```
wws runtimes --help

Usage: wws runtimes [OPTIONS] <COMMAND>

Commands:
install Install a new language runtime (like Ruby, Python, etc)
list List all available runtimes to install. By default, it uses the WebAssembly Language Runtime repository
check List of locally installed runtimes
uninstall Uninstall a language runtime
help Print this message or the help of the given subcommand(s)

Options:
--repo-url <REPO_URL> Set a different repository URL
--repo-name <REPO_NAME> Gives a name to the given repository URL
-h, --help Print help information
```

For a more complete documentation, please refer to the [Multiple Languages Runtimes](../features/multiple-language-runtimes.md) section.
Loading