$ npm install jsonp-body
Helper to create more safe jsonp response body for koa and other web framework.
npm install jsonp-body --save
const koa = require('koa');
const { jsonp } = require('jsonp-body');
var app = koa();
app.use(async function () {
this.set('X-Content-Type-Options', 'nosniff');
if (this.query.callback) {
this.set('Content-Type', 'text/javascript');
} else {
this.set('Content-Type', 'application/json');
}
this.body = jsonp({foo: 'bar'}, this.query.callback);
});
jsonp(obj, callback, options)Get obj jsonp string response with callback.
JSON.stringify
callback, default to 512JSON.stringify(obj, [replacer, [space]])JSON.stringify(obj, [replacer, [space]])Made with contributors-img.
© 2010 - cnpmjs.org x YWFE | Home | YWFE