Socket
Socket
Sign inDemoInstall

koa-file-server

Package Overview
Dependencies
30
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-file-server

file serving middleware for koa


Version published
Maintainers
6
Install size
1.55 MB
Created

Readme

Source

Koa File Server

NPM version build status Test coverage Gittip

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 app = require('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 - serve index.html files
  • hidden - show hidden files which leading .s

var file = yield* send(this, [path])

var send = require('koa-file-server')(options).send

serve.send() allows you to serve files as a utility. This is helpful for arbitrary paths. The middleware also adds var file = yield* this.fileServer.send(path).

path defaults to this.request.path.slice(1), removing the leading / to make the path relative.

For an example, see the middleware's source code.

var file = yield* push(this, path, [options])

var push = require('koa-file-server')(options).push

Optionally SPDY Push a file. The middleware also adds var file = yield* this.fileServer.send(path, [opts]).

Unlike send(), path is required. path must also be a relative path (without a leading /) relative to the root. The push stream's URL will be '/' + path. Errors will be thrown on unknown files. The only option is priority: 7.

Keywords

FAQs

Last updated on 11 Jun 2015

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