Skip to content

Instantly share code, notes, and snippets.

@cuu508
Created October 20, 2015 12:09
Show Gist options
  • Save cuu508/082a4c86aebfa4a832a5 to your computer and use it in GitHub Desktop.
Save cuu508/082a4c86aebfa4a832a5 to your computer and use it in GitHub Desktop.
location ~ ^/(\w\w\w\w\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w\w\w\w\w\w\w\w\w)/?$ {
add_header Content-Type text/plain;
postgres_pass database;
postgres_output value;
postgres_escape $ip $remote_addr;
postgres_escape $agent =$http_user_agent;
postgres_escape $body =$request_body;
postgres_query "
WITH t AS (
UPDATE api_check
SET last_ping=now()
WHERE code='$1'
RETURNING id, last_ping
)
INSERT INTO api_ping
(created, remote_addr, method, ua, body, owner_id, scheme)
SELECT
last_ping, $ip, '$request_method', $agent, $body, id, '$scheme'
FROM t
RETURNING 'OK'
";
postgres_rewrite no_changes 400;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment