Skip to content

keenwon/koa-response-jsonp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-response-jsonp

NPM version Node version Build Status Coverage Status npm download

koa jsonp middleware

Install

npm install koa-response-jsonp --save

Usage

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'
});