koa-static-server

Static file serving middleware for koa with directory, rewrite and index support

koa-static-server

KoaHub平台基于Node.js开发的Koa的rewrite and index support插件代码详情-LMLPHP
KoaHub平台基于Node.js开发的Koa的rewrite and index support插件代码详情-LMLPHP

static file serving middleware for koa with directory, rewrite and index support

Installation

点击(此处)折叠或打开

  1. $ npm install koa-static-server

API

点击(此处)折叠或打开

  1. var koa = require('koa')
  2. var app = koa()
  3. app.use(require('koa-static')(options))

Options

  • rootDir {string} directory that is to be served
  • rootPath {string} optional rewrite path
  • log {boolean} request access log to console
  • maxage Browser cache max-age in milliseconds. defaults to 0
  • hidden Allow transfer of hidden files. defaults to false
  • gzip Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.

Example

See examples for code examples

 

点击(此处)折叠或打开

  1. // example 'web' directory
  2. // web/index.html
  3. // web/file.txt
  4.  
  5. var serve = require('koa-static-server')
  6. var app = require('koa')()
  7.  
  8. // root index support
  9. // GET /
  10. // returns index.html
  11. // GET /file.txt
  12. // returns file.txt
  13. app.use(serve({rootDir: 'web'}))
  14.  
  15. // folder support
  16. // GET /web/
  17. // returns /web/index.html
  18. // GET /web/file.txt
  19. // returns /web/file.txt
  20. app.use(serve({rootDir: 'web', rootPath: '/web'}))
  21.  
  22. // index support
  23. // GET /
  24. // returns /file.txt
  25. app.use(serve({rootDir: 'web', index: 'file.txt'}))
  26.  
  27. // rewrite support
  28. // GET /web/
  29. // returns 404
  30. // GET /admin
  31. // returns /admin/index.html
  32. app.use(serve({rootDir: 'web', rootPath: '/admin'}))
  33.  
  34. app.listen(3000)
  35.  
  36. console.log('listening on port 3000')

Support

License

MIT

wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统
wemall地址:http://www.wemallshop.com
代码地址:http://js.koahub.com/home/feature/koa-static-server
KoaHub平台基于Node.js开发的Koa的rewrite and index support插件代码详情-LMLPHP
11-10 20:41