initial commit
This commit is contained in:
47
doc/examples/njs/README.md
Normal file
47
doc/examples/njs/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# print env via NJS
|
||||
|
||||
consult [Dockerfile](Dockerfile) or [docker-compose.yml](docker-compose.yml) - both are simple and fine enough.
|
||||
|
||||
---
|
||||
|
||||
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
|
||||
```
|
Reference in New Issue
Block a user