Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

silenceisgolden/koa-server-push

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-server-push

NPM version Build status Test coverage Dependency Status License Downloads

HTTP2 Server Push middleware for Koa

Installation

$ npm install koa-server-push

API

Usage for Koa 2.x (current version of node)

const Koa = require('koa');
const serverpush = require('koa-server-push');
const app = new Koa();

app.use(serverpush());
// OR
// app.use(serverpush({
//   manifestName: 'anothername.json',
//   gaeproxy: true,
//   singleheader: true
// }));

Options (optional)

  • manifestName The name of the manifest files. Defaults to 'push_manifest.json'.
  • gaeproxy Set the X-Associated-Content header as well. Defaults to false.
  • singleheader Set the Link header as a comma separated string instead of multiple Link headers. Defaults to false.

Example

'use strict';

const Koa = require('koa');
const serve = require('koa-static');
const convert = require('koa-convert');
const serverpush = require('koa-server-push');

const app = new Koa();

app.use(serverpush());
// OR
// app.use(serverpush({
//   manifestName: 'anothername.json',
//   gaeproxy: true,
//   singleheader: true
// }));
app.use(convert(serve('test/fixtures')));

/**
 * Note:
 * Please ensure that the server push middleware is not used after the
 * middleware that sets the response body and response type. This use case is
 * not supported at this time.
 */

app.listen(3000);

About

HTTP2 Server Push middleware for Koa

Resources

License

Stars

Watchers

Forks

Packages

No packages published