Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koajs/file-server
file serving middleware for koa
https://github.com/koajs/file-server
Last synced: 2 months ago
JSON representation
file serving middleware for koa
- Host: GitHub
- URL: https://github.com/koajs/file-server
- Owner: koajs
- License: mit
- Archived: true
- Created: 2014-03-23T21:12:51.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-24T12:01:07.000Z (over 8 years ago)
- Last Synced: 2024-04-14T13:08:39.789Z (8 months ago)
- Language: JavaScript
- Size: 35.2 KB
- Stars: 36
- Watchers: 8
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - file-server - file serving middleware for koa (Middleware)
- awesome-koa - koa-file-server - 具有附加功能的静态文件服务,如支持 etag 和 SPDY 推送。 ![](https://img.shields.io/github/stars/koajs/file-server.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-file-server.svg?style=flat-square) (仓库 / 中间件)
README
# Koa File Server
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Gittip][gittip-image]][gittip-url]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 supportDoes 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
```js
var app = require('koa')()
app.use(require('compress')())
app.use(require('koa-file-server')(options))
```Options are:
- `root` - 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])
```js
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])
```js
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`.[npm-image]: https://img.shields.io/npm/v/koa-file-server.svg?style=flat
[npm-url]: https://npmjs.org/package/koa-file-server
[travis-image]: https://img.shields.io/travis/koajs/file-server.svg?style=flat
[travis-url]: https://travis-ci.org/koajs/file-server
[coveralls-image]: https://img.shields.io/coveralls/koajs/file-server.svg?style=flat
[coveralls-url]: https://coveralls.io/r/koajs/file-server?branch=master
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat
[gittip-url]: https://www.gittip.com/jonathanong/