Authored by 周奇琪

接口文档生成模拟提交

... ... @@ -49,5 +49,8 @@ module.exports = {
},
'/ajax/link/:name': function(req, res) {
uploader.linkFile(req, res);
},
'/proxy':function (req,res) {
uploader.proxy(req,res);
}
}
\ No newline at end of file
... ...
... ... @@ -234,3 +234,14 @@ exports.getJSONFile=function(req,res){
console.log(searchDomain);
request.get("http://192.168.10.64:8080/yohosearch/brand/list.json").pipe(res);
}
exports.proxy = function(req,res) {
var headers = getHeader(req, res);
headers['Content-Type'] = 'application/json';
request({
headers:headers,
url:domain + req.query.url,
body:JSON.stringify(req.body)
}).pipe(res);
}
\ No newline at end of file
... ...
... ... @@ -53,9 +53,8 @@
<tr>
<th>属性名</th>
<th>属性类型</th>
<th>正则匹配</th>
<th>长度限制</th>
<th>说明</th>
<th>测试入参</th>
</tr>
</thead>
... ... @@ -64,9 +63,8 @@
<tr>
<td>{{name}}</td>
<td>{{type}}</td>
<td>{{reg}}</td>
<td>{{minLength}}-{{maxLength}}</td>
<td>{{message}}</td>
<td><input name="{{name}}" type="text" /></td>
</tr>
{{/ params}}
</tbody>
... ... @@ -75,7 +73,7 @@
<pre style="display:none">
</pre>
<button class="btn btn-success getRes" method="{{method}}" url="{{url}}">点击获取</button>
<button class="btn btn-success getRes" method="{{method}}" url="{{url}}" isjson="{{isJsonRaw}}">点击获取</button>
</div>
</div>
{{/ list}}
... ... @@ -169,19 +167,31 @@ var formatJson = function(json, options) {
return formatted;
};
$(function(){
$(".panel-minimize").click();
$(".getRes").click(function(){
$('.panel-minimize').click();
$('.getRes').click(function(){
var panel = $(this).prev().show('fast');
$.ajax({
url:$(this).attr("url"),
type:$(this).attr("method"),
dataType:'json'
}).done(function(data){
var isJson = $(this).attr('isjson');
var option = {
url:$(this).attr('url'),
type:$(this).attr('method'),
}
var data = {};
if(isJson) {
option.url = '/proxy?url=' + $(this).attr('url');
}
$(this).parent().find('input').each(function(){
data[$(this).attr('name')] = $(this).val();
});
option.data = data;
$.ajax(option).done(function(data){
var json = formatJson(data);
panel.html(json);
});
});
})
});
</script>
</body>
</html>
... ...