Skip to content

Commit a09fd6a

Browse files
committed
#1 #8 #9
1 parent 30c883b commit a09fd6a

File tree

16 files changed

+567
-248
lines changed

16 files changed

+567
-248
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ build: utils
2424

2525
configure-debug:
2626
cd $(NGX_PATH) && \
27-
./configure --with-cc-opt='-ggdb3 $(INC_FLAGS)'\
27+
CFLAGS="-ggdb3 $(INC_FLAGS)" ./configure \
2828
--prefix=$(PREFIX_PATH) \
2929
--add-module=$(MODULE_PATH) \
3030
--with-debug --with-ld-opt='$(LDFLAGS)'
@@ -59,7 +59,7 @@ test: utils build
5959
$(CUR_PATH)/test/nginx-tnt.sh
6060

6161
clean:
62-
$(MAKE) -C $(NGX_PATH) clean
62+
$(MAKE) -C $(NGX_PATH) clean 2>1 || echo "pass"
6363
rm -f misc/tp_{send,dump} misc/json2tp
6464

6565
utils: json2tp tp_dump

examples/echo.html

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<body>
1111
<div class='container' style='margin-top:50px;'>
1212
<div class="input-group input-group-lg">
13-
<input type='text' class='form-control' placeholder='{}' aria-describedby='sizing-addon1' id='input'>
13+
<input type='text' class='form-control' placeholder='echo [ { "hello": [ "world", "!" ] } ]' aria-describedby='sizing-addon1' id='input'>
1414
<span class='input-group-btn'>
1515
<button type='button' class='btn' id='submit'>execute</button>
1616
</span>
@@ -23,42 +23,50 @@
2323
<script>
2424
$(document).ready(function() {
2525

26-
var id = 0;
27-
var $out = $('#output');
26+
var id = 0,
27+
$input = $('#input'),
28+
$output = $('#output')
29+
;
2830

2931
function render(data) {
30-
$out.append('<div>[' + data.id + ']' + JSON.stringify(data) + '</div>');
32+
$output.append('<div>Ok [' + data.id + ']' + JSON.stringify(data) + '</div>');
3133
}
3234

3335
function render_error(data, stat, xhr) {
34-
if (data.status &&
35-
(data.status === 502 || data.status == 500))
36-
{
37-
$out.append('<div>tarantool backend failure</div>');
38-
}
36+
var stat = data.status;
37+
$output.append('<div> Failed [' + stat + '] ' + data.responseText + '</div>');
3938
}
4039

41-
$("#submit").click(function() {
40+
$("#submit").click(function(e) {
41+
42+
e.preventDefault();
43+
44+
var input_text = $input.val();
45+
46+
var method = input_text.substring(0, input_text.indexOf("[")),
47+
params = input_text.substring(input_text.indexOf("["),
48+
input_text.lenght);
4249

4350
try {
44-
var $input = $('#input');
45-
var call = JSON.stringify({
46-
method: 'call',
47-
params: ['echo', JSON.parse($input.val())],
48-
id: ++id
49-
});
51+
52+
var request = {
53+
method: method.replace(/ /g,''),
54+
id: ++id,
55+
params: JSON.parse(params)
56+
};
5057

5158
$.ajax({ type: 'POST',
5259
contentType: 'application/json; charset=utf-8',
5360
dataType: 'json',
54-
url: 'tnt',
55-
data: call,
61+
url: 'echo',
62+
data: JSON.stringify(request),
5663
success: render,
57-
error: render_error});
64+
error: render_error });
5865

5966
} catch (e) {
60-
$out.append('<div> Error:' + e + '</div>');
67+
$output.append('<div>Error: ' + e + '</div>');
6168
}
69+
6270
});
6371

6472
});

examples/echo.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
json=require('json');
22

3-
function call(a)
3+
function echo(a)
44
if type(a) == 'table' then
55
return {{a}}
66
end
@@ -9,7 +9,7 @@ end
99

1010
box.cfg {
1111
log_level = 5;
12-
listen = 9999;
12+
listen = 10001;
1313
}
1414

1515
if not box.space.tester then

misc/json2tp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ main(int argc, char **argv)
8787
if (rc == TP_TRANSCODE_OK) {
8888
size_t complete_msg_size = 0;
8989
if (tp_transcode_complete(&t, &complete_msg_size)
90-
!= TP_TRANSCODE_ERROR)
90+
!= TP_TRANSCODE_ERROR)
9191
fwrite(output, 1, complete_msg_size, out_file);
92-
else
93-
fprintf(stderr, "json2tp: failed to complete: '%s'\n", t.errmsg);
92+
else {
93+
fprintf(stderr, "json2tp: failed to complete, msg: %s\n",
94+
(t.errmsg ? t.errmsg : "unknown error"));
95+
}
9496
}
9597

9698
tp_transcode_free(&t);

misc/nginx.dev.conf

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ http {
2222
include mime.types;
2323
default_type application/octet-stream;
2424

25+
upstream echo {
26+
server 127.0.0.1:10001 max_fails=1 fail_timeout=30s;
27+
keepalive 1024;
28+
}
29+
2530
upstream tnt {
2631
server 127.0.0.1:9999 max_fails=1 fail_timeout=30s;
27-
server 127.0.0.1:9999 backup;
32+
server 127.0.0.1:10000 backup;
2833

29-
keepalive 1024;
34+
keepalive 1024;
3035
}
3136

3237
server {
@@ -35,6 +40,10 @@ http {
3540
autoindex off;
3641
server_name tnt_test;
3742

43+
location = /echo {
44+
tnt_pass echo;
45+
}
46+
3847
location = /tnt {
3948
tnt_pass tnt;
4049
}

0 commit comments

Comments
 (0)