nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.37k stars 323 forks source link

Cannot add js module names #961

Closed atsuoishimoto closed 1 year ago

atsuoishimoto commented 1 year ago

I tried to register a JS module following the instructions at https://unit.nginx.org/scripting/, but an error occurs.

I can upload the module just fine.

$ curl -X PUT --data-binary @http.js --unix-socket /usr/local/var/run/unit/control.sock http://localhost/js_modules/http
{
    "success": "JS module uploaded."
}

But I cannot add the module name to settings/js_module.

curl -X PUT -d '"http"' --unix-socket /usr/local/var/run/unit/control.sock http://localhost/config/settings/js_module
{
    "error": "Value doesn't exist."
}

I tried with Linux and macOS

Linux

Installed from https://packages.nginx.org/unit/debian/

unitd --version
unit version: 1.31.0
configured as ./configure --prefix=/usr --statedir=/var/lib/unit --control=unix:/var/run/control.unit.sock --runstatedir=/var/run --pid=/var/run/unit.pid --logdir=/var/log --log=/var/log/unit.log --tmpdir=/var/tmp --user=unit --group=unit --tests --openssl --njs --modulesdir=/usr/lib/unit/modules --libdir=/usr/lib/x86_64-linux-gnu --cc-opt='-g -O2 -ffile-prefix-map=/data/builder/debuild/unit-1.31.0/pkg/deb/debuild/unit-1.31.0=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
root@554f3f9cbb0e:/app/src# uname
Linux
root@554f3f9cbb0e:/app/src# uname -a
Linux 554f3f9cbb0e 5.15.49-linuxkit-pr #1 SMP Thu May 25 07:17:40 UTC 2023 x86_64 GNU/Linux

macOS

Installed with brew

unitd --version
unit version: 1.31.0
configured as ./configure --prefix=/usr/local/Cellar/unit/1.31.0 --sbindir=/usr/local/Cellar/unit/1.31.0/bin --logdir=/usr/local/var/log --log=/usr/local/var/log/unit/unit.log --runstatedir=/usr/local/var/run --pid=/usr/local/var/run/unit/unit.pid --control=unix:/usr/local/var/run/unit/control.sock --modules=/usr/local/lib/unit/modules --statedir=/usr/local/var/state/unit --tmpdir=/tmp --openssl --njs --cc-opt=-I/usr/local/opt/openssl@1.1/include --ld-opt=-L/usr/local/opt/openssl@1.1/lib

uname -a
Darwin mbp16.local 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:39:52 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_X86_64 x86_64 i386 Darwin
hongzhidao commented 1 year ago

Hi, Could you share you configuration with this?

curl --unix-socket /usr/local/var/run/unit/control.sock http://localhost/config

I wonder if the "setting" object exists.

lcrilly commented 1 year ago

@hongzhidao I suspect the same. In which case, this will work:

curl -X PUT -d '{"js_module": "http"}' --unix-socket /usr/local/var/run/unit/control.sock http://localhost/config/settings

Unit won't automatically create parent nodes in the configuration structure.

atsuoishimoto commented 1 year ago

@hongzhidao Just as you guessed, the "settings" is not exists.

 curl --unix-socket /usr/local/var/run/unit/control.sock http://localhost/config
{
        "listeners": {},
        "applications": {}
}

@lcrilly It works! I didn't expect to be able to make the key.

Thank you both very much.