Custom response from Tarantool + Nginx

189 Views Asked by At

Have instance: Nginx in DMZ with TNT_nginx_upstream_module + Tarantool Cartridge as API server.
When i have response with good result - it's 200 OK + JSON with data
How to set other response?

  • 400 Bad Request
  • 403 Forbidden
  • 404 Not found
  • 410 Gone
  • 500 Internal Server Error
  • 503 Service Unavailable
1

There are 1 best solutions below

0
On BEST ANSWER

The Tarantool Nginx upstream module has been designed to follow JSON RPC, not the generic HTTP. There is a way to return arbitrary results, using rewrite_by_lua in the location section. It looks like this:

location /api {
  default_type application/json;
  rewrite_by_lua '
    ...
  ';
}

I'm not pasting the full snippet here, as it is quite long. You can look it up here.

In general, I would also advise you to not use the mentioned upstream module if you want a generic HTTP API. It is better to use the HTTP server module written in Lua, and use Nginx as a regular reverse proxy. As a bonus, the Lua HTTP server comes on board of the cartridge module.