## Since I have JSON in my database, THIS WORKS for sending JSON directly from PostgreSQL to the browser:
http {
upstream db {
postgres_server 127.0.0.1 dbname=blah user=blah;
}
server {
listen 8080;
charset utf-8;
default_type application/json;
postgres_output value;
location ~ /things/(?<id>[0-9]+)$ {
postgres_pass db;
postgres_query "SELECT js FROM things WHERE id=$id";
}
}
}
But I also have the HTTP Status code in the browser, and I want to use it to set Nginx HTTP Status response. (I have PostgreSQL rigged-up to return status=404 and js='{}' when a record is not found. How I do that doesn't matter here, but point is...) EVERY query will always start with "SELECT status, js FROM " so I ALWAYS want the response.status to be HTTP status, and resonse.js to be the body of the response.
location ~ /things/(?<id>[0-9]+)$ {
postgres_pass db;
postgres_query "SELECT status, js FROM things WHERE id=$id";
}
Any suggestions on how to do this?
Thank you!