]> git.kaiwu.me - njs.git/commit
QuickJS: added native module support.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 3 Dec 2025 01:39:44 +0000 (17:39 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 12 Jan 2026 23:05:41 +0000 (15:05 -0800)
commit220b9b03033bc75a3548777a7e0914a07c2c0186
treeb41b75902dddeff291337438ceaba663b54ca141
parentf23297f57d984e85413e8ff902a80f0682889bc1
QuickJS: added native module support.

Added "js_load_http_native_module" and "js_load_stream_native_module"
main nginx.conf level directives. The directives load a dynamic
library. For security reason it is only allowed in the main context.
Later, JS code may import modules loaded with these directives
with standard import syntax.

example.conf:
    ...
    js_load_http_native_module /path/to/lib.so;
    js_load_http_native_module /path/to/lib2.so as lib2;

    http {
        js_import main.js;
...

main.js:
    import * as lib from 'lib.so';
    import * as lib2 from 'lib2';
    ...

See quickjs.h for the complete QuickJS API reference and
nginx/t/js_native_module.t for a working example.

This closes #968 feature request on Github.
nginx/config
nginx/ngx_http_js_module.c
nginx/ngx_js.c
nginx/ngx_js.h
nginx/ngx_stream_js_module.c
nginx/t/js_native_module.t [new file with mode: 0644]
nginx/t/stream_js_native_module.t [new file with mode: 0644]