Repository navigation
Expand file tree
/
Copy pathdefault.conf
More file actions
107 lines (86 loc) · 2.78 KB
/
Copy pathdefault.conf
File metadata and controls
107 lines (86 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
lua_package_path '/etc/jsonpath/?.lua;;';
access_log /var/log/access.log;
error_log /var/log/error.log info;
lua_shared_dict jsonpaths 1m;
init_by_lua_block {
local pathStrings = {
"$.store.book[*].author",
"$..author",
"$.store.*",
"$.store..price",
"$..book[2]",
"$..book[-2]",
"$..book[0,1]",
"$..book[:2]",
"$..book[1:2]",
"$..book[-2:]",
"$..book[2:]",
"$..book[?(@.isbn)]",
"$.store.book[?(@.price == 10)]",
"$..*",
"$..book[ ?( (@.price < 13 || $.store.bicycle.price < @.price) && @.price <=10 ) ]",
"$.store.book[?( (@.price < 10 || @.price > 10) && @.price > 10 )]",
"$..[?(@.originPrice > 1)]",
"$.pickBanner[?(@.originPrice > 1)]"
}
local jp = require("jsonpath")
jp.init("/etc/jsonpath/libjsonpath_lib.so")
local jsonpaths = ngx.shared.jsonpaths
for i, path in ipairs(pathStrings) do
jsonpaths:set(i, path)
jp.compile(path)
end
}
server {
listen 80;
server_name localhost;
gzip on;
gzip_types text/plain application/json;
#gzip_comp_level 6;
#gzip_vary on;
location / {
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;
}
location /filter {
# https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Accept-Encoding
proxy_set_header Accept-Encoding "*";
default_type 'text/plain';
rewrite /filter/(.*) /$1 break;
proxy_pass http://localhost;
header_filter_by_lua_block {
ngx.header["content-length"] = nil
local args = ngx.req.get_uri_args()
local jsonpaths = ngx.shared.jsonpaths
local path = jsonpaths:get(args['path'])
if path == nil then
ngx.exit(ngx.HTTP_BAD_REQUEST)
end
}
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 args = ngx.req.get_uri_args()
local path = ngx.shared.jsonpaths:get(args['path'])
local jsonpath = require("jsonpath")
local template = jsonpath.exec(path)
local json = buf .. chunk
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
}
}
}