• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

koajs/file-server: file serving middleware for koa

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

koajs/file-server

开源软件地址:

https://github.com/koajs/file-server

开源编程语言:

JavaScript 99.9%

开源软件介绍:

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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap