tarantool / nginx_upstream_module

Tarantool NginX upstream module (REST, JSON API, websockets, load balancing)
Other
174 stars 18 forks source link

How to return arbitrary result? #133

Open TvoroG opened 4 years ago

TvoroG commented 4 years ago

Thanks a lot for the module!

I want to wrap json object into callback:

callback({"foo": "bar"})

I don't know how to do that. I've tried to return result as simple string from tarantool with following nginx config:

tnt_pass router;
tnt_method 'foo_method';
tnt_pure_result on;
tnt_multireturn_skip_count 2;

But module returns it wrapped into double quotes

"callback({\"foo\": \"bar\"})"
snoopcatt commented 4 years ago

Please, show your foo_method code.

TvoroG commented 4 years ago

It simply returns a string

function foo_method()
    return 'callback({"foo": "bar"})'
end
snoopcatt commented 4 years ago

And what do you expect?

Totktonada commented 4 years ago

Try something like this: https://github.com/tarantool/nginx_upstream_module/tree/82355b8a1276ad584308f3ee4cc6e6129ecb302f#http-headers-and-status

TvoroG commented 4 years ago

I'm expecting callback({\"foo\": \"bar\"}) but it returns "callback({\"foo\": \"bar\"})".

Try something like this: https://github.com/tarantool/nginx_upstream_module/tree/82355b8a1276ad584308f3ee4cc6e6129ecb302f#http-headers-and-status

Thanks, but i was hoping to do it without lua on nginx.

Totktonada commented 4 years ago

I agree that it is not convenient to add extra logic on nginx side just to implement an API you need. AFAIU the module was initially made with RPC in a mind, that is why we need to preprocess-postprocess a request and a response to implement, say, restful API. However it would be good to change it in the future.

Totktonada commented 4 years ago

Hope we should not close the issue, but rather add an option that will do something like the Lua code that I linked above.