Skip to content

Commit

Permalink
添加debug信息
Browse files Browse the repository at this point in the history
  • Loading branch information
keenwon committed Sep 7, 2016
1 parent 458f6ee commit f2eda1b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/jsonp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,29 @@ function jsonp(app, options = {}) {
callbackFn = defaultcallbackFn;
}

debug(`callback function name: ${callbackFn}`);

app.context.jsonp = function (data) {
var callback = this.query[callbackFn];
var callback = this.query[callbackFn],
contentType = 'application/json',
response;

if (this.method !== 'GET') {
debug('the request mehtod is not "GET", return.');
return;
}

if (this.method !== 'GET' || !callback) {
if(!callback) {
debug(`${callbackFn} is undefined, return.`);
return;
}

this.type = 'application/json';
this.body = `${callback}(${JSON.stringify(data)})`;
response = `${callback}(${JSON.stringify(data)})`;

this.type = contentType;
this.body = response;

debug(`response: ${response}`);
}
}

Expand Down

0 comments on commit f2eda1b

Please sign in to comment.