Package Exports
- @ladjs/koa-better-static
- @ladjs/koa-better-static/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ladjs/koa-better-static) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@ladjs/koa-better-static
Static file serving middleware for Koa. Forked from an inactive project and maintained for Lad.
Table of Contents
Features
Our package @ladjs/koa-better-static is a high-performance, drop-in replacement for koa-static and is a modernized, Koa 2.x+ fork of koa-better-static (which is unmaintained and inactive).
- Uses a more optimal version of
koa-send - Supports
If-Modified-Sinceheader for cache/performance - Removal of
gzipoption (which checks for .gz files) - Removal of
defer(if you want this behavior, put the middleware at the end) - No default
indexfile - Faster performance with
findIndexhidden file lookup - Properly sets
Content-Typeheader usingmime-types
Install
npm:
npm install @ladjs/koa-better-staticUsage
This package exposes a function which accepts two arguments root (String - the path to serve assets from) and opts (an Object of options, see Options below).
const serve = require('@ladjs/koa-better-static');
const koa = require('koa');
const app = koa();
// GET /package.json
app.use(serve('.'));
// GET /hello.txt
app.use(serve('test/fixtures'));
// or use absolute paths
app.use(serve(__dirname + '/test/fixtures'));
app.listen(3000, () => {
console.log('listening on port 3000');
});Options
maxageBrowser cache max-age in milliseconds. defaults to0(maxAgecamelCase also works as a valid option alternative)hiddenAllow transfer of hidden files. defaults to falseindexDefault file name, defaults to noneifModifiedSinceSupportby sending a 304 (not modified) response. Defaults to trueformatAllow trailing slashes for directories (e.g. /directory and /directory. Defaults to true
Contributors
| Name | Website |
|---|---|
| Nick Baugh | http://niftylettuce.com/ |