node. JS Web QuickStart--Koahub.js components Koa-static-server

Source: Internet
Author: User
Tags browser cache

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
    • maxageBrowser cache max-age in milliseconds. Defaults to 0
    • hiddenAllow transfer of hidden files. Defaults to False
    • gzipTry 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.