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

$ npm install koa-static-server

API

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

Options

  • rootDir {string} directory that is to be server
  • 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

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

Support

License

MIT

官网

[http://js.koahub.com]http://js.koahub.com

Node.js web快速入门 -- KoaHub.js组件koa-static-server的更多相关文章

  1. Node.js web快速入门 -- KoaHub.js

    介绍 KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, Async & ...

  2. 基于 Koa.js 平台的 Node.js web 快速开发框架KoaHub.js demo 可安装

    KoaHub.js demo KoaHub.js KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Fu ...

  3. KoaHub.js是基于 Koa.js 平台的 Node.js web 快速开发框架

    koahubjs KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, A ...

  4. KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架之koahub-yilianyun

    koahub-yilianyun 微信易联云打印机接口 koahub-yilianyun易联云打印机node接口 Installation $ npm install koahub-yilianyun ...

  5. Node.js API快速入门

    Node.js API 快速入门 一.事件EventEmitter const EventEmitter = require('events'); class MyEmitter extends Ev ...

  6. Vue (一) --- vue.js的快速入门使用

    =-----------------------------------把现在的工作做好,才能幻想将来的事情,专注于眼前的事情,对于尚未发生的事情而陷入无休止的忧虑之中,对事情毫无帮助,反而为自己凭添 ...

  7. webpack快速入门——配置JS压缩,打包

    1 .首先在webpack.config.js中引入 const uglify = require('uglifyjs-webpack-plugin'); 2.然后在plugins配置里 plugin ...

  8. JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识

    JAVA WEB快速入门系列之前的相关文章如下:(文章全部本人[梦在旅途原创],文中内容可能部份图片.代码参照网上资源) 第一篇:JAVA WEB快速入门之环境搭建 第二篇:JAVA WEB快速入门之 ...

  9. JAVA WEB快速入门之从编写一个基于SpringMVC框架的网站了解Maven、SpringMVC、SpringJDBC

    接上篇<JAVA WEB快速入门之通过一个简单的Spring项目了解Spring的核心(AOP.IOC)>,了解了Spring的核心(AOP.IOC)后,我们再来学习与实践Maven.Sp ...

随机推荐

  1. lepus3.7 天兔监控安装手册 CentOS6.5+mysql5.6

    lepus3.7 天兔监控安装配置手册 CentOS6.5+mysql5.6 整体环境 192.168.1.250为监控机 192.168.1.248为被监控机 安装LAMP环境 [root@HE3~ ...

  2. oracle存储过程返回结果集

    http://www.2cto.com/database/201204/127180.html oracle实现存储过程返回查询结果集合的方法   --实现存储过程返回查询结果集合的方法 ,以下代码来 ...

  3. border-radius是向元素添加圆角边框的方法

    border-radius:10px; /* 所有角都使用半径为10px的圆角 */ border-radius: 5px 4px 3px 2px; /* 四个半径值分别是左上角.右上角.右下角和左下 ...

  4. 【.net 深呼吸】细说CodeDom(10):生成异常处理语句

    写完这一篇,大概可以准备过年了,就算是这系列文章的收尾吧. 异常处理语句,就是常说的try...catch语句,有时候,也会带有finally子句.要生成异常处理语句,得用到CodeTryCatchF ...

  5. 触摸滑动插件 Swiper

    Swiper Swiper  是纯javascript打造的滑动特效插件,面向手机.平板电脑等移动终端. Swiper中文网里已有详细的使用介绍,我就不多做介绍了. http://www.swiper ...

  6. MongoDB基础之九 replication复制集

    准备工作:创建目录 mkdir -p /home/m17 //home/m18 /home/m19 /home/mlog 1:启动3个实例,且声明实例属于某复制集 # ./bin/mongod --d ...

  7. 计算机程序的思维逻辑 (64) - 常见文件类型处理: 属性文件/CSV/EXCEL/HTML/压缩文件

    对于处理文件,我们介绍了流的方式,57节介绍了字节流,58节介绍了字符流,同时,也介绍了比较底层的操作文件的方式,60节介绍了随机读写文件,61节介绍了内存映射文件,我们也介绍了对象的序列化/反序列化 ...

  8. 如何增强ArcGIS插值图出图效果

    如何增强ArcGIS插值图出图效果 by 李远祥 在一些科研领域,经常会遇到使用插值的方式进行处理,并生成最终的插值图.插值图在ArcGIS里面非常容易生成,只要具备了采用点数据,通过ArcToolB ...

  9. 睡不着,复习一下C++基础中的基础(深拷贝与浅拷贝)

    #include <iostream> #include <string> #include <assert.h> using namespace std; //声 ...

  10. 初识XMLHttpRequeset

    XMLHttpRequeset是什么 XmlHttpRequest,可扩展的超文本传输歇息.从字面上理解:xml,可扩展的标记语言:http,超文本传送协议:request,请求.XmlHttpReq ...