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-serverApivar koa = require(' koa') var app = Koa() app. Use(require(' koa-static')(Options)) Options
rootDir
{String} directory
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 was gzip
supported by a client and if the requested file wit H .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.txtapp. Use(serve({rootdir: ' Web'}) //Folder support//get/web///Returns/web/index.html//Get/web/file.txt//Returns/web/file.txtApp.Use (< Span class= "Entity name function js" >serve ({rootdir: Web " Span class= "Meta delimiter object comma js" >, rootpath: /web ' }) ) /span> //Index support//GET///Returns/file.txtApp.Use (< Span class= "Entity name function js" >serve ({rootdir: Web " Span class= "Meta delimiter object comma js" >, index: File.txt ' }) ) /span> //rewrite support//get/web///returns 404//Get/admin//Returns/admin/index.htmlApp.Use (< Span class= "Entity name function js" >serve ({rootdir: Web " Span class= "Meta delimiter object comma js" >, rootpath: /admin ' }) ) /span> app. Listen(+) console. Log(' listening on port') Support
- Issues-open New Issue
- IRC-On
pkoretic
freenode
- Mail- [email protected]
License
MIT
Website
[http://js.koahub.com]http://js.koahub.com
Node. JS Web QuickStart--koahub.js component Koa-static-server