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. HDU-2573-Typing

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2573 这题把%s与gets()的输入法搞混了一直感觉没有错,就是找不出哪里错了, 题目思路不是很难. ...

  2. android 快捷技巧

    快捷方式 <!--[if !supportLists]-->0. Ctrl + 1 (快速修复) <!--[if !supportLists]-->1. Ctrl + D (删 ...

  3. 使用AIR进行移动APP开发常见功能和问题(上)

    1.  获取最近联系人 思路:侦听Geolocation的update事件,获取经度和纬度信息,再把坐标信息上传至服务器,服务器比较坐标信息算出距离,返回最近位置的若干个人. update时间在2种情 ...

  4. javascript与java编码互转

    java:java.net.URLEncoder.encode(s, "UTF-8");java.net.URLDecoder.decode(chezhanInEn,"U ...

  5. Debian8 安装wordpress博客

    首先要安装 php5-gd 已保证wordpress可以正常安装 下载Wordpress wget http://wordpress.org/latest.tar.gz 解压 tar -xzvf la ...

  6. Div.2 C. Dasha and Password

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. bootstrap-标签页

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Spring MVC 的环境搭建和入门小程序

    1.1.下载spring框架包. 1.1.1百度搜索Spring Framework. 进入spring官网,在网页右边选择想要下载的版本.如图 1.1.2进入页面按Ctrl+F搜索Distribut ...

  9. MySQL索引创建、删除、查看

    主键索引   PRIMARY KEY索引仅是一个具有名称PRIMARY的UNIQUE索引.这表示一个表只能包含一个PRIMARY KEY,因为一个表中不可能具有两个同名的索引. ALTER TABLE ...

  10. Java数组练习题小结

    //2015/07/07 //Java数组小小练习题 /* 3. 写一个函数,计算一个整数数组的平均值 4. 自定义一个整数数组a,读入一个整数n,如果n 在数组中存在,则输出n 的下标:如果不存在, ...