koa-request-pjax

1.0.2 • Public • Published

koa-request-pjax

A simple middleware to grab & set PJAX related headers

Installation

$ npm install koa-request-pjax --save

Usage

When this is a PJAX request, an object is set on the koa request:

this.request.pjax = {
  container: '#content'
}

You can alter this object to set PJAX response headers automatically:

// This will set the 'X-PJAX-URL' response header
this.request.pjax.url = "http://localhost:3000/foo/bar";
 
// This will set the 'X-PJAX-Version' response header
this.request.pjax.version = "v123";

Example

var koa = require('koa');
var pjax = require('koa-request-pjax');
var app = koa();
 
app.use(pjax());
app.use(function *(){
  this.body = 'Hello World';
  
  if (this.request.pjax) {
 
    /**
      * Do some PJAX-related magic here
      * ...
      */
    
    this.request.pjax.version = "v123";
    
    // Etc...
  }
});
 
app.listen(3000);

Readme

Keywords

none

Package Sidebar

Install

npm i koa-request-pjax

Weekly Downloads

1

Version

1.0.2

License

ISC

Last publish

Collaborators

  • eightyfive