Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename to createJsonpBody #9

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/extend/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const is = require('is-type-of');
const url = require('url');
const { JSONP_CONFIG, JSONP_WRAPPER } = require('../../lib/private_key');
const { JSONP_CONFIG } = require('../../lib/private_key');

module.exports = {
/**
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = {
yield next;

// generate jsonp body
this[JSONP_WRAPPER](this.body);
this.createJsonpBody(this.body);
};
},
};
Expand Down
11 changes: 6 additions & 5 deletions app/extend/context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const jsonpBody = require('jsonp-body');
const { JSONP_CONFIG, JSONP_WRAPPER } = require('../../lib/private_key');
const { JSONP_CONFIG } = require('../../lib/private_key');

module.exports = {
/**
Expand All @@ -12,12 +12,13 @@ module.exports = {
},

/**
* jsonp wrap body function
* set jsonp response wrap function, other plugin can use it.
* JSONP wrap body function
* Set jsonp response wrap function, other plugin can use it.
* If not necessary, please don't use this method in your application code.
* @param {Object} body respones body
* @public
* @private
*/
[JSONP_WRAPPER](body) {
createJsonpBody(body) {
const jsonpConfig = this[JSONP_CONFIG];
if (!jsonpConfig || !jsonpConfig.jsonpFunction) {
this.body = body;
Expand Down
1 change: 0 additions & 1 deletion lib/private_key.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

exports.JSONP_CONFIG = Symbol('jsonp#config');
exports.JSONP_WRAPPER = Symbol.for('jsonp#wrapper');
2 changes: 1 addition & 1 deletion test/fixtures/jsonp-test/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = app => {
try {
yield next;
} catch (error) {
this[Symbol.for('jsonp#wrapper')]({ msg: error.message });
this.createJsonpBody({ msg: error.message });
}
}, app.jsonp(), 'jsonp.error');
};