Socket
Socket
Sign inDemoInstall

@ladjs/koa-better-static

Package Overview
Dependencies
9
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ladjs/koa-better-static

Static file serving middleware for koa


Version published
Weekly downloads
4
decreased by-73.33%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

@ladjs/koa-better-static

build status code coverage code style styled with prettier made with lass license npm downloads

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-Since header for cache/performance
  • Removal of gzip option (which checks for .gz files)
  • Removal of defer (if you want this behavior, put the middleware at the end)
  • No default index file

Install

npm:

npm install @ladjs/koa-better-static

yarn:

yarn add @ladjs/koa-better-static

Usage

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

  • maxage Browser cache max-age in milliseconds. defaults to 0 (maxAge camelCase also works as a valid option alternative)
  • hidden Allow transfer of hidden files. defaults to false
  • index Default file name, defaults to none
  • ifModifiedSinceSupport by sending a 304 (not modified) response. Defaults to true
  • format Allow trailing slashes for directories (e.g. /directory and /directory. Defaults to true

Contributors

NameWebsite
Nick Baughhttp://niftylettuce.com/

License

MIT © Nick Baugh

Keywords

FAQs

Last updated on 09 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc