Chinaunix首页 | 论坛 | 博客
  • 博客访问: 53262
  • 博文数量: 48
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-12 11:48
文章分类
文章存档

2016年(48)

我的朋友

分类: JavaScript

2016-11-08 11:56:34

koa-static-server

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


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

点击(此处)折叠或打开

  1. $ npm install koa-static-server

点击(此处)折叠或打开

  1. var koa = require('koa')
  2. var app = koa()
  3. app.use(require('koa-static')(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.

See  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')

  • Issues - 
  • IRC - pkoretic on freenode

MIT

wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统
wemall地址:
代码地址:
阅读(466) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~