1
0
angie-conv-image/doc/examples/njs/README.md

61 lines
854 B
Markdown

# print env via NJS
Dockerfile:
```dockerfile
FROM docker.io/rockdrilla/angie-conv:v0.0.4
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:
```nginx
server {
listen 8080;
location / { return 204; }
js_import ngx_env.js;
location = /env
{
js_content ngx_env.report;
}
}
```
---
NJS script:
```js
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`:
```sh
curl http://127.0.0.1:8080/env
```