Koa File Server
An opinionated file server. Designed to sit behind a CDN.
-
sha256
etags and consequential 304s - Caches
fs.stat()
calls - Caches etag calculations
- OPTIONS and 405 support
-
index.html
files - Optionally serve hidden files
- Caches gzipped versions of files
- SPDY Push support
Does not support:
- Dynamic files - assumes static files never change. You will have to delete files from the cache yourself if files change.
- Directory listing
- Path decoding
API
var Koa = require('koa')
var app = new Koa()
app.use(require('compress')())
app.use(require('koa-file-server')(options))
Options are:
-
root
<process.cwd()> - root directory. nothing above this root directory can be served -
maxage
- cache control max age -
etag
- options for etags-
algorithm
- hashing algorithm to use -
encoding
- encoding to use
-
-
index
- serveindex.html
files -
hidden
- show hidden files which leading.
s -
push
- will automatically try and use server push -
files
[] - array of files (relative toroot
) to be server pushed -
pushOptions
{} - options to be passed to spdy push method (e.g. priority)- The only
pushOption
ispriority: 1-7
.
- The only
-
link
- will set link headers based onfiles
option