This middleware simply sets a xhr
boolean on koa's ctx.state
namespace.
This aims to be the equivalent of Express req.xhr
$ npm install koa-request-xhr --save
var koa = require('koa');
var xhr = require('koa-request-xhr');
var app = koa();
app.use(xhr());
app.use(function *(){
if (this.state.xhr) {
this.body = { message: 'Hello World' };
} else {
this.body = 'Hello World';
}
});
app.listen(3000);