Welcome! Log In Create A New Profile

Advanced

Re: NJS - API Calls

naidile.pn
June 04, 2019 02:46PM
Thanks a lot! It's working. I had underscore in header which was causing
unexpected behavior as such headers get ignored.


On Tue, Jun 4, 2019 at 6:25 PM Dmitry Volyntsev <xeioex@nginx.com> wrote:

>
>
> On 04.06.2019 14:00, naidile.pn wrote:
> > What does api write=on; mean ? Could you please explain.
> >
>
>
> api is a plus-only nginx module
> (http://nginx.org/en/docs/http/ngx_http_api_module.html).
>
> You do not need this to make subrequests.
>
>
> > On Tue, Jun 4, 2019 at 4:26 PM naidile.pn http://naidile.pn
> > <naidilepn@gmail.com <mailto:naidilepn@gmail.com>> wrote:
> >
> > Hi Dmitry,
> >
> > I tried subrequest. But it doesn't work. Nginx is trying find the
> > API within /var/www/html folder.
>
>
> Can you elaborate more what are you trying to do?
>
> See the config below as an example:
>
> -----------------
> http {
> js_include proxy.js;
> js_set $summary summary;
> js_set $prop prop;
>
> # proxy server
>
> server {
> listen 8080;
> server_name localhost;
>
> location / {
> js_content proxy;
> }
>
> location = /_prop {
> internal;
> proxy_pass http://127.0.0.1:8090;
> }
>
> location = /_proxy {
> internal;
> proxy_set_header Prop $prop;
> proxy_pass http://127.0.0.1:8070$request_uri;
> }
> }
>
> # prop server
>
> server {
> listen 8090;
>
> location / {
> return 200 '{"prop": "WAKA"}';
> }
> }
>
> # dest server
>
> server {
> listen 8070;
>
> location / {
> return 200 $summary;
> }
> }
> }
>
> -----------------
> function proxy(r) {
> r.subrequest("/_prop", reply => {
> if (reply.status != 200) {
> r.return(500);
> return;
> }
>
> r.variables.prop = JSON.parse(reply.responseBody).prop;
> r.subrequest("/_proxy", res => {
> r.return(res.status != 200 ? 500 : 200,
> res.responseBody);
> })
> });
> }
>
> function summary(r) {
> var s = "JS summary\n\n";
>
> s += "Method: " + r.method + "\n";
> s += "HTTP version: " + r.httpVersion + "\n";
> s += "Host: " + r.headersIn.host + "\n";
> s += "Remote Address: " + r.remoteAddress + "\n";
> s += "URI: " + r.uri + "\n";
>
> s += "Headers:\n";
>
> for (var h in r.headersIn) {
> s += " header '" + h + "' is '" + r.headersIn[h] + "'\n";
> }
>
> return s;
> }
>
> var prop = (r) => r.variables.prop;
> -----------------
> curl http://127.0.0.1:8080/test
> JS summary
>
> Method: GET
> HTTP version: 1.0
> Host: 127.0.0.1:8070
> Remote Address: 127.0.0.1
> URI: /test
> Headers:
> header 'Prop' is 'WAKA'
> header 'Host' is '127.0.0.1:8070'
> header 'Connection' is 'close'
> header 'User-Agent' is 'curl/7.64.0'
> header 'Accept' is '*/*'
>
> -----------------
>
> >
> > And, with proxy_pass within subrequest, I'm not able to pass the
> > request headers and body. Kindly help here.
>
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

NJS - API Calls

naidile.pn 308 June 03, 2019 01:30PM

Re: NJS - API Calls

Dmitry Volyntsev 157 June 03, 2019 01:40PM

Re: NJS - API Calls

naidile.pn 144 June 03, 2019 01:46PM

Re: NJS - API Calls

naidile.pn 225 June 03, 2019 01:48PM

Re: NJS - API Calls

Dmitry Volyntsev 139 June 03, 2019 02:04PM

Re: NJS - API Calls

naidile.pn 149 June 03, 2019 02:10PM

Re: NJS - API Calls

Dmitry Volyntsev 137 June 03, 2019 02:16PM

Re: NJS - API Calls

naidile.pn 139 June 03, 2019 02:22PM

Re: NJS - API Calls

naidile.pn 138 June 04, 2019 05:14AM

Re: NJS - API Calls

Dmitry Volyntsev 153 June 04, 2019 05:32AM

Re: NJS - API Calls

Dmitry Volyntsev 177 June 04, 2019 08:56AM

Re: NJS - API Calls

naidile.pn 183 June 04, 2019 02:46PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 263
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready