Skip to content

Middleware for koajs 2 to check if the incoming request is an Ajax request.

Notifications You must be signed in to change notification settings

bjufre/koa-isajax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-isajax

Express req.xhr equivalent for Koa 2 applications. Middleware for Koa 2 that sets a boolean on the ctx.state on whether or not the request is and Ajax request.

This middleware is the equivalent to Express req.xhr.

Installation

$ npm install koa-isajax --save

Example

import Koa from 'koa';
import isajax from 'koa-isajax';

const app = new Koa();

app.use(isajax());
app.use(async (ctx) => {
    if (ctx.state.xhr) {
        // Ajax request.
    } else  {
        // Not ajax request.
    }
});

app.listen(3000);

About

Middleware for koajs 2 to check if the incoming request is an Ajax request.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published