1.0.2 • Published 8 years ago

koa-request-pjax v1.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

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);
1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.1

9 years ago