koa jsonp middleware
npm install koa-response-jsonp --save
const Koa = require('koa');
const app = new Koa();
const jsonp = require('koa-response-jsonp');
jsonp(app);
app.use(async ctx => {
ctx.jsonp({
success: true
});
});
app.listen(3000);
then you request http://localhost:3000?callback=fn
will response:
fn({"success":true})
custom callback functoin name:
jsonp(app, {
callbackFn: 'cb'
});