红联Linux门户
Linux帮助

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

发布时间:2016-11-08 14:14:09来源:红联作者:wemallshop
koa-static-server

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


static file serving middleware for koa with directory, rewrite and index support
Installation[code]$ npm install koa-static-server[/code]API[code]var koa = require('koa')
var app = koa()
app.use(require('koa-static')(options))[/code]Options

[list]
[*]rootDir {string} directory that is to be served
[/list]
[list]
[*]rootPath {string} optional rewrite path
[/list]
[list]
[*]log {boolean} request access log to console
[/list]
[list]
[*]maxage Browser cache max-age in milliseconds. defaults to 0
[/list]
[list]
[*]hidden Allow transfer of hidden files. defaults to false
[/list]
[list]
[*]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.
[/list]
Example
See examples for code examples[code]// example 'web' directory
// web/index.html
// web/file.txt

var serve = require('koa-static-server')
var app = require('koa')()

// root index support
// GET /
// returns index.html
// GET /file.txt
// returns file.txt
app.use(serve({rootDir: 'web'}))

// folder support
// GET /web/
// returns /web/index.html
// GET /web/file.txt
// returns /web/file.txt
app.use(serve({rootDir: 'web', rootPath: '/web'}))

// index support
// GET /
// returns /file.txt
app.use(serve({rootDir: 'web', index: 'file.txt'}))

// rewrite support
// GET /web/
// returns 404
// GET /admin
// returns /admin/index.html
app.use(serve({rootDir: 'web', rootPath: '/admin'}))

app.listen(3000)

console.log('listening on port 3000')[/code]Support
[list]
[*]Issues - open new issue
[/list]
[list]
[*]IRC - pkoretic on freenode
[/list]
License
MIT
wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统
wemall地址:http://www.wemallshop.com
代码地址:http://js.koahub.com/home/feature/koa-static-server
文章评论

共有 1 条评论

  1. duanshupeng 于 2017-06-21 10:38:14发表:

    66