2019-08-23 22:09:09 +09:00
|
|
|
lua_package_path '/etc/jsonpath/?.lua;;';
|
|
|
|
|
2019-08-25 15:43:04 +09:00
|
|
|
access_log /var/log/nginx_access.log;
|
2019-08-23 22:09:09 +09:00
|
|
|
error_log /var/log/nginx_error.log info;
|
|
|
|
|
2019-09-08 15:37:21 +09:00
|
|
|
init_by_lua_block {
|
|
|
|
jp = require("jsonpath")
|
|
|
|
jp.init("/etc/jsonpath/libjsonpath_lib.so")
|
|
|
|
|
|
|
|
BOOK = "$..book"
|
|
|
|
jp.compile(BOOK)
|
|
|
|
|
|
|
|
COMMENT_COUNT = "$..commit[?(@.author.name == 'Thibault Charbonnier')]"
|
|
|
|
jp.compile(COMMENT_COUNT)
|
|
|
|
}
|
|
|
|
|
2019-08-23 22:09:09 +09:00
|
|
|
server {
|
2019-09-08 15:37:21 +09:00
|
|
|
listen 80;
|
|
|
|
server_name localhost;
|
|
|
|
|
|
|
|
gzip on;
|
|
|
|
gzip_types text/plain application/json;
|
|
|
|
#gzip_comp_level 6;
|
|
|
|
#gzip_vary on;
|
|
|
|
|
|
|
|
location ~ \.json {
|
|
|
|
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
|
|
|
|
expires off;
|
|
|
|
|
|
|
|
default_type 'text/plain';
|
|
|
|
root /etc/jsonpath/example;
|
2019-08-23 22:09:09 +09:00
|
|
|
}
|
|
|
|
|
2019-08-25 15:43:04 +09:00
|
|
|
location /1 {
|
2019-09-08 15:37:21 +09:00
|
|
|
default_type text/plain;
|
|
|
|
content_by_lua_file /etc/jsonpath/testa.lua;
|
|
|
|
}
|
2019-08-25 15:43:04 +09:00
|
|
|
|
2019-09-08 15:37:21 +09:00
|
|
|
location /2 {
|
|
|
|
# https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Accept-Encoding
|
|
|
|
proxy_set_header Accept-Encoding "*";
|
|
|
|
|
|
|
|
default_type 'text/plain';
|
|
|
|
|
|
|
|
proxy_pass 'http://localhost/example.json';
|
|
|
|
|
|
|
|
header_filter_by_lua_block {
|
|
|
|
ngx.header.content_length = nil
|
2019-08-25 15:43:04 +09:00
|
|
|
}
|
|
|
|
|
2019-09-08 15:37:21 +09:00
|
|
|
body_filter_by_lua_block {
|
|
|
|
local chunk, eof = ngx.arg[1], ngx.arg[2]
|
|
|
|
local buf = ngx.ctx.buf
|
|
|
|
|
|
|
|
if eof then
|
|
|
|
if buf then
|
|
|
|
local json = buf .. chunk
|
|
|
|
local template = jp.compile(BOOK)
|
|
|
|
local result = template(json)
|
|
|
|
ngx.arg[1] = result
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if buf then
|
|
|
|
ngx.ctx.buf = buf .. chunk
|
|
|
|
else
|
|
|
|
ngx.ctx.buf = chunk
|
|
|
|
end
|
|
|
|
|
|
|
|
ngx.arg[1] = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
location /3 {
|
|
|
|
# https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Accept-Encoding
|
|
|
|
proxy_set_header Accept-Encoding "*";
|
|
|
|
|
|
|
|
default_type 'text/plain';
|
|
|
|
|
|
|
|
proxy_pass 'https://api.github.com/repos/openresty/lua-nginx-module/commits';
|
|
|
|
|
|
|
|
header_filter_by_lua_block {
|
|
|
|
ngx.header.content_length = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
body_filter_by_lua_block {
|
|
|
|
local chunk, eof = ngx.arg[1], ngx.arg[2]
|
|
|
|
local buf = ngx.ctx.buf
|
|
|
|
|
|
|
|
if eof then
|
|
|
|
if buf then
|
|
|
|
local json = buf .. chunk
|
|
|
|
local template = jp.compile(COMMENT_COUNT)
|
|
|
|
local result = template(json)
|
|
|
|
ngx.arg[1] = result
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if buf then
|
|
|
|
ngx.ctx.buf = buf .. chunk
|
|
|
|
else
|
|
|
|
ngx.ctx.buf = chunk
|
|
|
|
end
|
|
|
|
|
|
|
|
ngx.arg[1] = nil
|
|
|
|
}
|
2019-08-23 22:09:09 +09:00
|
|
|
}
|
|
|
|
}
|