WASM Module#
The core module that implements basic WASM functionality in Angie: it includes support for loading alternative runtimes and WASM modules, as well as configuring their features and limits.
The other modules in this section extend this functionality, allowing you to flexibly configure and optimize WASM capabilities for various scenarios and requirements.
In our repositories, the module is built dynamically
and is available as a separate package named Default — wasm_modules Loads a module from a disk file and assigns it a unique identifier
(required parameter). During loading, verification occurs to ensure the module
can be instantiated. The directive supports the following parameters: Allows the guest to access a directory on the host.
The parameter can be specified multiple times for different directories. Explicitly restricts the list of APIs allowed for the module by listing them.
If the module attempts to use unavailable APIs (not listed here),
an "API not found" error is returned. By default, all APIs are available to the module. Controls the lifecycle of the loaded module. In In A top-level directive that provides the configuration file context
in which WASM directives should be specified.
It can contain commands for loading WASM modules and configuring parameters
specific to a particular runtime.angie-module-wasm
.Configuration Example#
# These directives load the core functionality
load_module modules/ngx_wasm_module.so;
load_module modules/ngx_wasm_core_module.so;
load_module modules/ngx_wasmtime_module.so;
# Available here: https://git.angie.software/web-server/angie-wasm
load_module modules/ngx_http_wasm_host_module.so;
events {
}
wasm_modules {
#use wasmtime;
load ngx_http_handler.wasm id=handler;
load ngx_http_vars.wasm id=vars type=reactor;
}
http {
wasm_var vars "ngx:wasi/var-utils#sum-entry" $rvar $arg_a $arg_b $arg_c $arg_d;
server {
listen *:8080;
location / {
return 200 "sum('$arg_a','$arg_b','$arg_c','$arg_d')=$rvar\n";
}
location /wasm {
client_max_body_size 20M;
wasm_content handler "ngx:wasi/http-handler-entry#handle-request";
}
}
}
Directives#
load#
load
file id=
identifier [fs=
host_path:guest_path]... [api=
api]... [type=
command
| reactor
]fs
api
type
command
mode, the machine executes once
and its state is destroyed after execution.reactor
mode, the machine effectively runs indefinitely,
allowing code to be executed multiple times.
This requires careful memory management:
if resources are not freed, memory leaks can occur.wasm_modules#