Merge branch 'master' into next

This commit is contained in:
Lloyd Brookes
2015-11-19 10:18:58 +00:00
5 changed files with 104 additions and 16 deletions

View File

@ -14,7 +14,7 @@ module.exports = {
},
{
name: 'compress', alias: 'c', type: Boolean,
description: 'Enable gzip compression, reduces bandwidth.', group: 'server'
description: 'Serve gzip-compressed resources, where applicable', group: 'server'
},
{
name: 'forbid', alias: 'b', type: String, multiple: true, typeLabel: '[underline]{path} ...',
@ -26,7 +26,7 @@ module.exports = {
},
{
name: 'rewrite', alias: 'r', type: String, multiple: true, typeLabel: '[underline]{expression} ...',
description: "A list of URL rewrite rules, e.g. '/from -> /to'", group: 'server'
description: "A list of URL rewrite rules. For each rule, separate the 'from' and 'to' routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from -> /to'", group: 'server'
},
{
name: 'spa', alias: 's', type: String, typeLabel: '[underline]{file}',

View File

@ -11,18 +11,27 @@ let debug
module.exports = localWebServer
/**
* Returns a Koa application
* Returns a Koa application you can launch or mix into an existing app.
*
* @param [options] {object} - options
* @param [options.static] {object} - koajs/static config
* @param [options.static] {object} - koa-static config
* @param [options.static.root] {string} - root directory
* @param [options.static.options] {string} - options
* @param [options.static.options] {string} - [options](https://github.com/koajs/static#options)
* @param [options.serveIndex] {object} - koa-serve-index config
* @param [options.serveIndex.path] {string} - root directory
* @param [options.serveIndex.options] {string} - options
* @param [options.forbid] {string[]} - a list of forbidden routes.
* @param [options.serveIndex.options] {string} - [options](https://github.com/expressjs/serve-index#options)
* @param [options.forbid] {string[]} - A list of forbidden routes, each route being an [express route-path](http://expressjs.com/guide/routing.html#route-paths).
* @param [options.spa] {string} - specify an SPA file to catch requests for everything but static assets.
* @param [options.log] {object} - [morgan](https://github.com/expressjs/morgan) config
* @param [options.log.format] {string} - [log format](https://github.com/expressjs/morgan#predefined-formats)
* @param [options.log.options] {object} - [options](https://github.com/expressjs/morgan#options)
* @param [options.compress] {boolean} - Serve gzip-compressed resources, where applicable
* @param [options.mime] {object} - A list of mime-type overrides, passed directly to [mime.define()](https://github.com/broofa/node-mime#mimedefine)
* @param [options.rewrite] {module:local-web-server~rewriteRule[]} - One or more rewrite rules
* @param [options.verbose] {boolean} - Print detailed output, useful for debugging
*
* @alias module:local-web-server
* @return {external:KoaApplication}
* @example
* const localWebServer = require('local-web-server')
* localWebServer().listen(8000)
@ -244,3 +253,27 @@ function mockResponses (options) {
process.on('unhandledRejection', (reason, p) => {
throw reason
})
/**
* The `from` and `to` routes are specified using [express route-paths](http://expressjs.com/guide/routing.html#route-paths)
*
* @example
* ```json
* {
* "rewrite": [
* { "from": "/css/*", "to": "/build/styles/$1" },
* { "from": "/npm/*", "to": "http://registry.npmjs.org/$1" },
* { "from": "/:user/repos/:name", "to": "https://api.github.com/repos/:user/:name" }
* ]
* }
* ```
*
* @typedef rewriteRule
* @property from {string} - request route
* @property to {string} - target route
*/
/**
* @external KoaApplication
* @see https://github.com/koajs/koa/blob/master/docs/api/index.md#application
*/