docs.. log-format alias changed.. forbid option
This commit is contained in:
48
README.md
48
README.md
@ -5,44 +5,42 @@
|
|||||||
[](https://github.com/feross/standard)
|
[](https://github.com/feross/standard)
|
||||||
|
|
||||||
# local-web-server
|
# local-web-server
|
||||||
A static web-server for productive front-end development.
|
A simple web-server for productive front-end development.
|
||||||
|
|
||||||
**Requires node v4.0.0 or higher**.
|
**Requires node v4.0.0 or higher**.
|
||||||
|
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
From the folder you wish to serve, run:
|
Serve a directory on the default port:
|
||||||
```sh
|
```sh
|
||||||
$ ws
|
$ ws
|
||||||
serving at http://localhost:8000
|
serving at http://localhost:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
If you wish to serve a different directory, run:
|
Blacklist certain paths, for example config files:
|
||||||
```sh
|
```sh
|
||||||
$ ws -d ~/mysite/
|
$ ws --forbid .json .yml
|
||||||
serving /Users/Lloyd/mysite at http://localhost:8000
|
serving at http://localhost:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
If you wish to override the default port (8000), use `--port` or `-p`:
|
Reduce bandwidth with gzip compression:
|
||||||
```sh
|
|
||||||
$ ws --port 9000
|
|
||||||
serving at http://localhost:9000
|
|
||||||
```
|
|
||||||
|
|
||||||
To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
|
|
||||||
```sh
|
```sh
|
||||||
$ ws --compress
|
$ ws --compress
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Specify a Single Page Application:
|
||||||
|
```sh
|
||||||
|
$ ws --spa index.html
|
||||||
|
```
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
|
Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
|
||||||
|
|
||||||
### Globally
|
|
||||||
```sh
|
```sh
|
||||||
$ npm install -g local-web-server
|
$ npm install -g local-web-server
|
||||||
```
|
```
|
||||||
|
|
||||||
### Bundled with your project
|
## Distribute with your project
|
||||||
```sh
|
```sh
|
||||||
$ npm install local-web-server --save-dev
|
$ npm install local-web-server --save-dev
|
||||||
```
|
```
|
||||||
@ -71,24 +69,6 @@ $ npm install
|
|||||||
$ npm start
|
$ npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
### Logging
|
|
||||||
Passing a value to `--log-format` will write an access log to `stdout`.
|
|
||||||
|
|
||||||
Either use a built-in [morgan](https://github.com/expressjs/morgan) logger preset:
|
|
||||||
```sh
|
|
||||||
$ ws --log-format short
|
|
||||||
```
|
|
||||||
|
|
||||||
Or a custom [morgan](https://github.com/expressjs/morgan) log format:
|
|
||||||
```sh
|
|
||||||
$ ws -f ':method -> :url'
|
|
||||||
```
|
|
||||||
|
|
||||||
Or silence:
|
|
||||||
```sh
|
|
||||||
$ ws -f none
|
|
||||||
```
|
|
||||||
|
|
||||||
## Storing default options
|
## Storing default options
|
||||||
To store per-project options, saving you the hassle of inputting them everytime, store them in the `local-web-server` property of your project's `package.json`:
|
To store per-project options, saving you the hassle of inputting them everytime, store them in the `local-web-server` property of your project's `package.json`:
|
||||||
```json
|
```json
|
||||||
@ -139,7 +119,7 @@ You can set additional mime-type/extension mappings, or override the defaults by
|
|||||||
## Log Visualisation
|
## Log Visualisation
|
||||||
Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation).
|
Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation).
|
||||||
|
|
||||||
# API Reference
|
## API Reference
|
||||||
|
|
||||||
<a name="module_local-web-server"></a>
|
<a name="module_local-web-server"></a>
|
||||||
## local-web-server
|
## local-web-server
|
||||||
@ -152,7 +132,7 @@ Returns a Koa application
|
|||||||
| Param | Type | Description |
|
| Param | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| [options] | <code>object</code> | options |
|
| [options] | <code>object</code> | options |
|
||||||
| [options.blacklist] | <code>Array.<regexp></code> | a list of forbidden routes. |
|
| [options.forbid] | <code>Array.<regexp></code> | a list of forbidden routes. |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
|
@ -40,14 +40,14 @@ localWebServer({
|
|||||||
log: { format: options.server['log-format'] },
|
log: { format: options.server['log-format'] },
|
||||||
compress: options.server.compress,
|
compress: options.server.compress,
|
||||||
mime: options.server.mime,
|
mime: options.server.mime,
|
||||||
blacklist: options.server.blacklist.map(regexp => RegExp(regexp, "i")),
|
forbid: options.server.forbid.map(regexp => RegExp(regexp, "i")),
|
||||||
proxyRoutes: options.server.proxyRoutes,
|
proxyRoutes: options.server.proxyRoutes,
|
||||||
spa: options.server.spa,
|
spa: options.server.spa,
|
||||||
'no-cache': options.server['no-cache']
|
'no-cache': options.server['no-cache']
|
||||||
}).listen(options.server.port, onServerUp)
|
}).listen(options.server.port, onServerUp)
|
||||||
|
|
||||||
function halt (err) {
|
function halt (err) {
|
||||||
console.log(ansi.format(`Error: ${err.stack}`, 'red'))
|
console.log(ansi.format(`Error: ${err.message}`, 'red'))
|
||||||
console.log(usage)
|
console.log(usage)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ function collectOptions () {
|
|||||||
root: process.cwd(), // root dir when using multiple static dirs
|
root: process.cwd(), // root dir when using multiple static dirs
|
||||||
directory: process.cwd(),
|
directory: process.cwd(),
|
||||||
proxyRoutes: [],
|
proxyRoutes: [],
|
||||||
blacklist: []
|
forbid: []
|
||||||
}
|
}
|
||||||
|
|
||||||
/* override built-in defaults with stored config and then command line args */
|
/* override built-in defaults with stored config and then command line args */
|
||||||
|
@ -5,44 +5,42 @@
|
|||||||
[](https://github.com/feross/standard)
|
[](https://github.com/feross/standard)
|
||||||
|
|
||||||
# local-web-server
|
# local-web-server
|
||||||
A static web-server for productive front-end development.
|
A simple web-server for productive front-end development.
|
||||||
|
|
||||||
**Requires node v4.0.0 or higher**.
|
**Requires node v4.0.0 or higher**.
|
||||||
|
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
From the folder you wish to serve, run:
|
Serve a directory on the default port:
|
||||||
```sh
|
```sh
|
||||||
$ ws
|
$ ws
|
||||||
serving at http://localhost:8000
|
serving at http://localhost:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
If you wish to serve a different directory, run:
|
Blacklist certain paths, for example config files:
|
||||||
```sh
|
```sh
|
||||||
$ ws -d ~/mysite/
|
$ ws --forbid .json .yml
|
||||||
serving /Users/Lloyd/mysite at http://localhost:8000
|
serving at http://localhost:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
If you wish to override the default port (8000), use `--port` or `-p`:
|
Reduce bandwidth with gzip compression:
|
||||||
```sh
|
|
||||||
$ ws --port 9000
|
|
||||||
serving at http://localhost:9000
|
|
||||||
```
|
|
||||||
|
|
||||||
To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
|
|
||||||
```sh
|
```sh
|
||||||
$ ws --compress
|
$ ws --compress
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Specify a Single Page Application:
|
||||||
|
```sh
|
||||||
|
$ ws --spa index.html
|
||||||
|
```
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
|
Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
|
||||||
|
|
||||||
### Globally
|
|
||||||
```sh
|
```sh
|
||||||
$ npm install -g local-web-server
|
$ npm install -g local-web-server
|
||||||
```
|
```
|
||||||
|
|
||||||
### Bundled with your project
|
## Distribute with your project
|
||||||
```sh
|
```sh
|
||||||
$ npm install local-web-server --save-dev
|
$ npm install local-web-server --save-dev
|
||||||
```
|
```
|
||||||
@ -71,24 +69,6 @@ $ npm install
|
|||||||
$ npm start
|
$ npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
### Logging
|
|
||||||
Passing a value to `--log-format` will write an access log to `stdout`.
|
|
||||||
|
|
||||||
Either use a built-in [morgan](https://github.com/expressjs/morgan) logger preset:
|
|
||||||
```sh
|
|
||||||
$ ws --log-format short
|
|
||||||
```
|
|
||||||
|
|
||||||
Or a custom [morgan](https://github.com/expressjs/morgan) log format:
|
|
||||||
```sh
|
|
||||||
$ ws -f ':method -> :url'
|
|
||||||
```
|
|
||||||
|
|
||||||
Or silence:
|
|
||||||
```sh
|
|
||||||
$ ws -f none
|
|
||||||
```
|
|
||||||
|
|
||||||
## Storing default options
|
## Storing default options
|
||||||
To store per-project options, saving you the hassle of inputting them everytime, store them in the `local-web-server` property of your project's `package.json`:
|
To store per-project options, saving you the hassle of inputting them everytime, store them in the `local-web-server` property of your project's `package.json`:
|
||||||
```json
|
```json
|
||||||
@ -139,7 +119,7 @@ You can set additional mime-type/extension mappings, or override the defaults by
|
|||||||
## Log Visualisation
|
## Log Visualisation
|
||||||
Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation).
|
Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation).
|
||||||
|
|
||||||
# API Reference
|
## API Reference
|
||||||
|
|
||||||
{{>main}}
|
{{>main}}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ module.exports = {
|
|||||||
description: 'Web server port', group: 'server'
|
description: 'Web server port', group: 'server'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'log-format', alias: 'f', type: String,
|
name: 'log-format', alias: 'l', type: String,
|
||||||
description: "If a format is supplied an access log is written to stdout. If not, a statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url').", group: 'server'
|
description: "If a format is supplied an access log is written to stdout. If not, a statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url').", group: 'server'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -17,6 +17,10 @@ module.exports = {
|
|||||||
description: 'Enable gzip compression, reduces bandwidth.', group: 'server'
|
description: 'Enable gzip compression, reduces bandwidth.', group: 'server'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: 'forbid', alias: 'f', type: String, multiple: true, typeLabel: '[underline]{regexp} ...',
|
||||||
|
description: 'A list of forbidden routes', group: 'server'
|
||||||
|
},
|
||||||
|
{
|
||||||
name: 'no-cache', alias: 'n', type: Boolean,
|
name: 'no-cache', alias: 'n', type: Boolean,
|
||||||
description: 'Disable etag-based caching - forces loading from disk each request.', group: 'server'
|
description: 'Disable etag-based caching - forces loading from disk each request.', group: 'server'
|
||||||
},
|
},
|
||||||
|
@ -27,7 +27,7 @@ module.exports = localWebServer
|
|||||||
* Returns a Koa application
|
* Returns a Koa application
|
||||||
*
|
*
|
||||||
* @param [options] {object} - options
|
* @param [options] {object} - options
|
||||||
* @param [options.blacklist] {regexp[]} - a list of forbidden routes.
|
* @param [options.forbid] {regexp[]} - a list of forbidden routes.
|
||||||
* @alias module:local-web-server
|
* @alias module:local-web-server
|
||||||
* @example
|
* @example
|
||||||
* const localWebServer = require('local-web-server')
|
* const localWebServer = require('local-web-server')
|
||||||
@ -38,7 +38,7 @@ function localWebServer (options) {
|
|||||||
serveIndex: {},
|
serveIndex: {},
|
||||||
log: {},
|
log: {},
|
||||||
compress: false,
|
compress: false,
|
||||||
blacklist: [],
|
forbid: [],
|
||||||
directories: [],
|
directories: [],
|
||||||
proxyRoutes: []
|
proxyRoutes: []
|
||||||
}, options)
|
}, options)
|
||||||
@ -82,9 +82,9 @@ function localWebServer (options) {
|
|||||||
app.use(cors())
|
app.use(cors())
|
||||||
|
|
||||||
/* path blacklist */
|
/* path blacklist */
|
||||||
if (options.blacklist.length) {
|
if (options.forbid.length) {
|
||||||
app.use(function pathBlacklist (ctx, next) {
|
app.use(function blacklist (ctx, next) {
|
||||||
if (options.blacklist.some(regexp => regexp.test(ctx.path))) {
|
if (options.forbid.some(regexp => regexp.test(ctx.path))) {
|
||||||
ctx.throw(403, http.STATUS_CODES[403])
|
ctx.throw(403, http.STATUS_CODES[403])
|
||||||
} else {
|
} else {
|
||||||
return next()
|
return next()
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
"http-proxy": "^1.12.0",
|
"http-proxy": "^1.12.0",
|
||||||
"kcors": "^1.0.1",
|
"kcors": "^1.0.1",
|
||||||
"koa": "^2.0.0-alpha.3",
|
"koa": "^2.0.0-alpha.3",
|
||||||
"koa-charset": "^1.1.4",
|
|
||||||
"koa-compress": "^1.0.8",
|
"koa-compress": "^1.0.8",
|
||||||
"koa-conditional-get": "^1.0.3",
|
"koa-conditional-get": "^1.0.3",
|
||||||
"koa-convert": "^1.1.0",
|
"koa-convert": "^1.1.0",
|
||||||
@ -45,12 +44,11 @@
|
|||||||
"koa-send": "^3.1.0",
|
"koa-send": "^3.1.0",
|
||||||
"koa-serve-index": "^1.1.0",
|
"koa-serve-index": "^1.1.0",
|
||||||
"koa-static": "^1.5.2",
|
"koa-static": "^1.5.2",
|
||||||
"morgan": "^1.0.0",
|
|
||||||
"path-to-regexp": "^1.2.1",
|
"path-to-regexp": "^1.2.1",
|
||||||
"req-then": "^0.2.2",
|
|
||||||
"stream-log-stats": "^v1.1.0-0"
|
"stream-log-stats": "^v1.1.0-0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"req-then": "^0.2.2",
|
||||||
"tape": "^4.2.2"
|
"tape": "^4.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user