Crates.io | zenoh-plugin-webserver |
lib.rs | zenoh-plugin-webserver |
version | 1.0.2 |
source | src |
created_at | 2022-12-07 17:45:16.270802 |
updated_at | 2024-11-08 13:55:12.993931 |
description | Plugin for Zenoh implementing an HTTP server that maps URLs to zenoh key expressions |
homepage | http://zenoh.io |
repository | https://github.com/eclipse-zenoh/zenoh-plugin-webserver |
max_upload_size | |
id | 732011 |
size | 71,525 |
The Eclipse Zenoh: Zero Overhead Pub/sub, Store/Query and Compute.
Zenoh (pronounce /zeno/) unifies data in motion, data at rest and computations. It carefully blends traditional pub/sub with geo-distributed storages, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks.
Check the website zenoh.io and the roadmap for more detailed information.
The Web Server plugin implements an HTTP server mapping URLs to zenoh keys.
This plugin can be used to set-up a Web server where the resources are retrieved from geo-distributed
zenoh storages, each leveraging various backends (file system, database, memory...).
Library name zenoh_plugin_webserver
:point_right: Download stable versions: https://download.eclipse.org/zenoh/zenoh-plugin-webserver/
:point_right: Build "main" branch: see below
The following documentation related to the version currently in development in "main" branch: 0.6.x.
For previous versions see the README and code of the corresponding tagged version:
Assuming you have a static website, you can:
Here are the steps:
Make sure the libraries for the File System backend and the Web Server plugin are available for the zenoh router:
either installing their packages (depending your platform), either downloading the library files corresponding
to your platform in your ~/.zenoh/lib
directory.
Copy the website files into a ~/.zenoh/zbackend_fs/my-site
directory (or make it a symbolic link to the path of your website)
Create a zenoh.json5
configuration file containing:
{
plugins: {
webserver: {
http_port: 8080,
},
storage_manager: {
volumes: {
fs: {}
},
storages: {
demo: {
key_expr: "my-site/**",
strip_prefix: "my-site",
volume: {
id: "fs",
dir: "my-site",
read_only: true
}
}
}
}
}
}
Start the zenoh router (zenohd
). It will automatically load the Web Server plugin and make it available on port 8080. It will also create a storage replying to any zenoh query on key expressions starting with my-site/
.
Now you can browse your site on http://localhost:8080/my-site.
For more advanced use cases you can also:
my-site/
zenoh key.eval
function for a resource, replying to requests with a
dynamic content (see the z_eval
example in
Rust or
Python).In its configuration part, the plugin supports those settings:
http_port
- int or string - required:"<local_ip>:<port_number>"
If in zenohd
logs you see such error log at startup:
[2021-04-12T14:20:51Z ERROR zenoh_plugin_webserver] Unable to start http server for REST : Os { code: 48, kind: AddrInUse, message: "Address already in use" }
It means another process is already using this port number that the webserver plugin would like to use. In such case, you have 2 solutions:
listener
option.If in zenohd
logs you see such error log at startup:
[2021-04-12T13:55:10Z ERROR zenoh_plugin_webserver] Unable to start http server for REST : Os { code: 13, kind: PermissionDenied, message: "Permission denied"
It probably means your OS (this usually happens on Linux) forbids the usage of the configured port for non-root user (actually it usually restricts all ports between 0 and 1024). In such case, you have 2 solutions:
sudo
)listener
option.:warning: WARNING :warning: : Zenoh and its ecosystem are under active development. When you build from git, make sure you also build from git any other Zenoh repository you plan to use (e.g. binding, plugin, backend, etc.). It may happen that some changes in git are not compatible with the most recent packaged Zenoh release (e.g. deb, docker, pip). We put particular effort in mantaining compatibility between the various git repositories in the Zenoh project.
:warning: WARNING :warning: : As Rust doesn't have a stable ABI, the plugins should be built with the exact same Rust version than
zenohd
, and using forzenoh
dependency the same version (or commit number) than 'zenohd'. Otherwise, incompatibilities in memory mapping of shared types betweenzenohd
and the library can lead to a"SIGSEV"
crash.
At first, install Cargo and Rust. If you already have the Rust toolchain installed, make sure it is up-to-date with:
$ rustup update
To know the Rust version you're zenohd
has been built with, use the --version
option.
Example:
$ zenohd --version
The zenoh router v0.6.0-beta.1 built with rustc 1.64.0 (a55dd71d5 2022-09-19)
Here, zenohd
has been built with the rustc version 1.64.0
.
Install and use this toolchain with the following command:
$ rustup default 1.64.0
And zenohd
version corresponds to an un-released commit with id 1f20c86
. Update the zenoh
dependency in Cargo.lock with this command:
$ cargo update -p zenoh --precise 1f20c86
Then build the backend with:
$ cargo build --release -p zenoh-plugin-webserver