initial commit
This commit is contained in:
6
doc/examples/njs/Dockerfile
Normal file
6
doc/examples/njs/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
|
||||
## load ngx_http_js_module
|
||||
ENV NGX_HTTP_MODULES='njs'
|
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
|
||||
```
|
13
doc/examples/njs/docker-compose.yml
Normal file
13
doc/examples/njs/docker-compose.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
|
||||
angie-conv-example-njs:
|
||||
container_name: angie-conv-example-njs
|
||||
image: docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
environment:
|
||||
NGX_HTTP_MODULES: 'njs'
|
||||
ports:
|
||||
- "127.0.0.1:8080:8080"
|
||||
volumes:
|
||||
- "./site:/angie/site:ro"
|
11
doc/examples/njs/site/http-env-js.conf
Normal file
11
doc/examples/njs/site/http-env-js.conf
Normal file
@@ -0,0 +1,11 @@
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
location / { return 204; }
|
||||
|
||||
js_import ngx_env.js;
|
||||
location = /env
|
||||
{
|
||||
js_content ngx_env.report;
|
||||
}
|
||||
}
|
12
doc/examples/njs/site/ngx_env.js
Normal file
12
doc/examples/njs/site/ngx_env.js
Normal file
@@ -0,0 +1,12 @@
|
||||
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 };
|
Reference in New Issue
Block a user