Koahub platform based on node. JS developed KOA rewrite and index support plug-in code details

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-server
Api
var koa = require (' KOA ') var app = Koa () App.use (Require (' koa-static ') (options))
Options
    • rootDir{string} directory is served
    • 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.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//G et/web///returns 404//Get/admin//Returns/admin/index.html App.use (Serve ({rootdir: ' Web ', RootPath: '/admin '})) AP P.listen (Console.log) (' Listening on Port 3000 ')
Support
    • Issues-open New Issue
    • IRC-On pkoretic freenode
License

MIT

Wemall Open Source Micro-mall, mall, mall source code, three levels of distribution, micro-fresh, micro-fruit, micro-takeaway, micro-ordering---professional system wemall Address: http://www.wemallshop.com
Code Address: Http://js.koahub.com/home/feature/koa-static-server

Koahub platform based on node. JS developed KOA rewrite and index support plug-in code details

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.