1
0
angie-conv-image/doc/examples/njs
2024-09-20 22:51:44 +03:00
..
site doc: examples 2024-09-20 01:27:15 +03:00
Dockerfile doc: examples 2024-09-20 01:27:15 +03:00
README.md doc: update examples 2024-09-20 22:51:44 +03:00

print env via NJS

Dockerfile:

FROM docker.io/rockdrilla/angie-conv:v0.0.1

COPY /site/ /etc/angie/site/

## install 'angie-module-njs' and process package contents
RUN apt-install-angie-mod.sh njs ; \
    apt-clean.sh

## load ngx_http_js_module
ENV NGX_HTTP_MODULES='njs'

configuration:

server {
    listen 8080;

    location / { return 204; }

    js_import ngx_env.js;
    location = /env
    {
        js_content ngx_env.report;
    }
}

NJS script:

function report(r) {
    var s = "";
    const keys = Object.keys(process.env).sort();
    for (const i in keys) {
        const k = keys[i];
        const v = process.env[k];
        s += k + '=' + v + "\n";
    }
    r.return(200, s);
}

export default { report };

Test URI e.g. with curl:

curl http://127.0.0.1:8080/env