Maison > php教程 > php手册 > le corps du texte

基于Node开发的KoaHub的静态服务器重写和索引代码

WBOY
Libérer: 2016-10-09 08:32:16
original
1443 Les gens l'ont consulté

基于 Koa平台Node.js开发的KoaHub.js的静态服务器重写和索引代码
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
APIvar koa = require('koa')<br> var app = koa()<br> app.use(require('koa-static')(options))<br> Options<br> <br> rootDir {string} directory that is to be server<br> rootPath {string} optional rewrite path<br> log {boolean} request access log to console<br> maxage Browser cache max-age in milliseconds. defaults to 0<br> hidden Allow transfer of hidden files. defaults to false<br> 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.<br> <br> Example<br> <br> See examples for code examples<br> <br> // example 'web' directory <br> // web/index.html <br> // web/file.txt <br>  <br> var serve = require('koa-static-server')<br> var app = require('koa')()<br>  <br> // root index support <br> // GET / <br> // returns index.html <br> // GET /file.txt <br> // returns file.txt <br> app.use(serve({rootDir: 'web'}))<br>  <br> // folder support <br> // GET /web/ <br> // returns /web/index.html <br> // GET /web/file.txt <br> // returns /web/file.txt <br> app.use(serve({rootDir: 'web', rootPath: '/web'}))<br>  <br> // index support <br> // GET / <br> // returns /file.txt <br> app.use(serve({rootDir: 'web', index: 'file.txt'}))<br>  <br> // rewrite support <br> // GET /web/ <br> // returns 404 <br> // GET /admin <br> // returns /admin/index.html <br> app.use(serve({rootDir: 'web', rootPath: '/admin'}))<br>  <br> app.listen(3000)<br>  <br> console.log('listening on port 3000')<br> Support<br> <br> Issues - open new issue<br> IRC - pkoretic on freenode<br> mail - petar.koretic@gmail.com<br> LicenseMIT
来源:http://js.koahub.com
基于Node开发的KoaHub的静态服务器重写和索引代码

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!