sirv-auto-push

Middleware for express based apps which serves static files via sirv using h2-auto-push

Usage no npm install needed!

<script type="module">
  import sirvAutoPush from 'https://cdn.skypack.dev/sirv-auto-push';
</script>

README

sirv-auto-push

Middleware for express based apps which serves static files via sirv using h2-auto-push.

Getting started

Using npm

npm i -S sirv-auto-push

Using yarn

yarn add sirv-auto-push

Usage

const express = require('express');
const sirvAp = require('sirv-auto-push');

const app = express();

app.use(sirvAp("static", { dev: IS_DEV }));

app.get('/', function (req, res) {
  res.send('Hello World!');
});

app.listen(3000, function () {
  console.log('Server listening on port 3000');
});

API

sirvAp(dir, opts={})

Returns: Function

The returned function is a middleware in the standard Express-like signature: (req, res, next), where req is the http.IncomingMessage, res is the http.ServerResponse, and next (in this case) is the function to call if no file was found for the given path.

dir

Type: String
Default: .

The directory from which to read and serve assets. It is resolved to an absolute path — you must provide an absolute path yourself if process.cwd() is not the correct assumption.

opts.prefix

Type: String
Default: /

Record file for auto pushing only when the path starts with prefix.

opts.cacheConfig

See h2-auto-push api for cache config

...opts

See sirv api for rest options

License

MIT © Andrey Grandilevskiy