https://github.com/eightyfive/koa-request-pjax
Koa middleware to grab & set PJAX related headers
https://github.com/eightyfive/koa-request-pjax
Last synced: 6 months ago
JSON representation
Koa middleware to grab & set PJAX related headers
- Host: GitHub
- URL: https://github.com/eightyfive/koa-request-pjax
- Owner: eightyfive
- Created: 2015-11-04T04:37:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-26T07:29:43.000Z (over 10 years ago)
- Last Synced: 2025-02-23T13:22:51.909Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```js
this.request.pjax = {
container: '#content'
}
```
You can alter this `object` to set PJAX response headers automatically:
```js
// 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
```js
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);
```