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)
|
||||
|
||||
# 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**.
|
||||
|
||||
## Synopsis
|
||||
|
||||
From the folder you wish to serve, run:
|
||||
Serve a directory on the default port:
|
||||
```sh
|
||||
$ ws
|
||||
serving at http://localhost:8000
|
||||
```
|
||||
|
||||
If you wish to serve a different directory, run:
|
||||
Blacklist certain paths, for example config files:
|
||||
```sh
|
||||
$ ws -d ~/mysite/
|
||||
serving /Users/Lloyd/mysite at http://localhost:8000
|
||||
$ ws --forbid .json .yml
|
||||
serving at http://localhost:8000
|
||||
```
|
||||
|
||||
If you wish to override the default port (8000), use `--port` or `-p`:
|
||||
```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)
|
||||
Reduce bandwidth with gzip compression:
|
||||
```sh
|
||||
$ ws --compress
|
||||
```
|
||||
|
||||
Specify a Single Page Application:
|
||||
```sh
|
||||
$ ws --spa index.html
|
||||
```
|
||||
|
||||
## Install
|
||||
Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
|
||||
|
||||
### Globally
|
||||
```sh
|
||||
$ npm install -g local-web-server
|
||||
```
|
||||
|
||||
### Bundled with your project
|
||||
## Distribute with your project
|
||||
```sh
|
||||
$ npm install local-web-server --save-dev
|
||||
```
|
||||
@ -71,24 +69,6 @@ $ npm install
|
||||
$ 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
|
||||
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
|
||||
@ -139,7 +119,7 @@ You can set additional mime-type/extension mappings, or override the defaults by
|
||||
## 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>
|
||||
## local-web-server
|
||||
@ -152,7 +132,7 @@ Returns a Koa application
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [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**
|
||||
```js
|
||||
|
@ -40,14 +40,14 @@ localWebServer({
|
||||
log: { format: options.server['log-format'] },
|
||||
compress: options.server.compress,
|
||||
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,
|
||||
spa: options.server.spa,
|
||||
'no-cache': options.server['no-cache']
|
||||
}).listen(options.server.port, onServerUp)
|
||||
|
||||
function halt (err) {
|
||||
console.log(ansi.format(`Error: ${err.stack}`, 'red'))
|
||||
console.log(ansi.format(`Error: ${err.message}`, 'red'))
|
||||
console.log(usage)
|
||||
process.exit(1)
|
||||
}
|
||||
@ -77,7 +77,7 @@ function collectOptions () {
|
||||
root: process.cwd(), // root dir when using multiple static dirs
|
||||
directory: process.cwd(),
|
||||
proxyRoutes: [],
|
||||
blacklist: []
|
||||
forbid: []
|
||||
}
|
||||
|
||||
/* override built-in defaults with stored config and then command line args */
|
||||
|
@ -5,44 +5,42 @@
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
# 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**.
|
||||
|
||||
## Synopsis
|
||||
|
||||
From the folder you wish to serve, run:
|
||||
Serve a directory on the default port:
|
||||
```sh
|
||||
$ ws
|
||||
serving at http://localhost:8000
|
||||
```
|
||||
|
||||
If you wish to serve a different directory, run:
|
||||
Blacklist certain paths, for example config files:
|
||||
```sh
|
||||
$ ws -d ~/mysite/
|
||||
serving /Users/Lloyd/mysite at http://localhost:8000
|
||||
$ ws --forbid .json .yml
|
||||
serving at http://localhost:8000
|
||||
```
|
||||
|
||||
If you wish to override the default port (8000), use `--port` or `-p`:
|
||||
```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)
|
||||
Reduce bandwidth with gzip compression:
|
||||
```sh
|
||||
$ ws --compress
|
||||
```
|
||||
|
||||
Specify a Single Page Application:
|
||||
```sh
|
||||
$ ws --spa index.html
|
||||
```
|
||||
|
||||
## Install
|
||||
Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
|
||||
|
||||
### Globally
|
||||
```sh
|
||||
$ npm install -g local-web-server
|
||||
```
|
||||
|
||||
### Bundled with your project
|
||||
## Distribute with your project
|
||||
```sh
|
||||
$ npm install local-web-server --save-dev
|
||||
```
|
||||
@ -71,24 +69,6 @@ $ npm install
|
||||
$ 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
|
||||
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
|
||||
@ -139,7 +119,7 @@ You can set additional mime-type/extension mappings, or override the defaults by
|
||||
## 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}}
|
||||
|
||||
|
@ -5,7 +5,7 @@ module.exports = {
|
||||
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'
|
||||
},
|
||||
{
|
||||
@ -17,6 +17,10 @@ module.exports = {
|
||||
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,
|
||||
description: 'Disable etag-based caching - forces loading from disk each request.', group: 'server'
|
||||
},
|
||||
|
@ -27,7 +27,7 @@ module.exports = localWebServer
|
||||
* Returns a Koa application
|
||||
*
|
||||
* @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
|
||||
* @example
|
||||
* const localWebServer = require('local-web-server')
|
||||
@ -38,7 +38,7 @@ function localWebServer (options) {
|
||||
serveIndex: {},
|
||||
log: {},
|
||||
compress: false,
|
||||
blacklist: [],
|
||||
forbid: [],
|
||||
directories: [],
|
||||
proxyRoutes: []
|
||||
}, options)
|
||||
@ -82,9 +82,9 @@ function localWebServer (options) {
|
||||
app.use(cors())
|
||||
|
||||
/* path blacklist */
|
||||
if (options.blacklist.length) {
|
||||
app.use(function pathBlacklist (ctx, next) {
|
||||
if (options.blacklist.some(regexp => regexp.test(ctx.path))) {
|
||||
if (options.forbid.length) {
|
||||
app.use(function blacklist (ctx, next) {
|
||||
if (options.forbid.some(regexp => regexp.test(ctx.path))) {
|
||||
ctx.throw(403, http.STATUS_CODES[403])
|
||||
} else {
|
||||
return next()
|
||||
|
@ -33,7 +33,6 @@
|
||||
"http-proxy": "^1.12.0",
|
||||
"kcors": "^1.0.1",
|
||||
"koa": "^2.0.0-alpha.3",
|
||||
"koa-charset": "^1.1.4",
|
||||
"koa-compress": "^1.0.8",
|
||||
"koa-conditional-get": "^1.0.3",
|
||||
"koa-convert": "^1.1.0",
|
||||
@ -45,12 +44,11 @@
|
||||
"koa-send": "^3.1.0",
|
||||
"koa-serve-index": "^1.1.0",
|
||||
"koa-static": "^1.5.2",
|
||||
"morgan": "^1.0.0",
|
||||
"path-to-regexp": "^1.2.1",
|
||||
"req-then": "^0.2.2",
|
||||
"stream-log-stats": "^v1.1.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"req-then": "^0.2.2",
|
||||
"tape": "^4.2.2"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user