Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subRequest to a named location #17

Closed
vigie opened this issue Jun 9, 2018 · 2 comments
Closed

subRequest to a named location #17

vigie opened this issue Jun 9, 2018 · 2 comments

Comments

@vigie
Copy link

vigie commented Jun 9, 2018

Hi

I'd like my njs function to manipulate the req body and then send it along to a private location that is not exposed in the conf file as a public location. I tried

req.subrequest('@myNamedLocation', ...

and

req.subrequest('http://my.private.url', ...

but in both cases nginx looked in the html folder for a file with these names.

Please advise on how I can best achieve this use case.

Thanks,
Matt

@xeioex
Copy link
Contributor

xeioex commented Jun 9, 2018

Hi @vigie,

Unfortunately it is not possible to make a subrequest to a named location due to limitation of the nginx internal API. But you can make a subrequest to an internal location which is protected from the outside. Please, take a look: http://nginx.org/en/docs/http/ngx_http_core_module.html#internal

for example:

var my_body = process(req.body);
req.subrequest('/internal', {body:my_body}, 
                           function(reply) {res.return(reply.status == 200 ? 200 : 500)})

@vigie
Copy link
Author

vigie commented Jun 10, 2018

This is exactly what I was looking for, internal had escaped me somehow.

Thanks very much for the quick help @xeioex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants