2024-09-20 01:27:15 +03:00
|
|
|
# print env via NJS
|
|
|
|
|
2024-09-20 22:51:44 +03:00
|
|
|
Dockerfile:
|
|
|
|
|
|
|
|
```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'
|
|
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
2024-09-20 01:27:15 +03:00
|
|
|
configuration:
|
|
|
|
|
|
|
|
```nginx
|
|
|
|
server {
|
|
|
|
listen 8080;
|
|
|
|
|
|
|
|
location / { return 204; }
|
|
|
|
|
|
|
|
js_import ngx_env.js;
|
|
|
|
location = /env
|
|
|
|
{
|
|
|
|
js_content ngx_env.report;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-09-20 22:51:44 +03:00
|
|
|
---
|
|
|
|
|
2024-09-20 01:27:15 +03:00
|
|
|
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 };
|
|
|
|
```
|
|
|
|
|
2024-09-20 22:51:44 +03:00
|
|
|
---
|
2024-09-20 01:27:15 +03:00
|
|
|
|
|
|
|
Test URI e.g. with `curl`:
|
|
|
|
```sh
|
|
|
|
curl http://127.0.0.1:8080/env
|
|
|
|
```
|