2014-05-01 11:28:15 +01:00
[](https://www.npmjs.org/package/local-web-server)
2015-11-15 21:15:25 +00:00
[](https://www.npmjs.org/package/local-web-server)
2017-03-23 23:26:15 +00:00
[](https://travis-ci.org/lwsjs/local-web-server)
[](https://david-dm.org/lwsjs/local-web-server/next)
2015-10-30 11:31:59 +00:00
[](https://github.com/feross/standard)
2017-03-23 21:42:21 +00:00
[](https://gitter.im/lwsjs/local-web-server?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2014-01-24 19:49:11 +01:00
2017-05-14 23:06:20 +01:00
***Requires node v7.6 or higher. Install the [previous release ](https://github.com/lwsjs/local-web-server/tree/v1.x ) for node >= v4.0.0. Documentation still WIP.***
2015-11-20 09:52:51 +00:00
2015-02-01 14:04:17 +00:00
# local-web-server
2015-11-26 21:12:49 +00:00
2017-05-14 23:06:20 +01:00
The development web server for productive front-end and full-stack Javascript engineers. Built on [lws ](https://github.com/lwsjs/lws ).
2016-06-20 20:32:32 +01:00
2017-03-23 23:17:14 +00:00
**Features**
2016-06-20 20:32:32 +01:00
2017-05-14 23:06:20 +01:00
- Fast and lightweight.
- Use the built-in features, a subset of the built-ins or your own feature stack
- Configurable with sensible defaults.
- Configure by constructor option, command-line option, stored config or all three.
2017-03-27 10:11:00 +01:00
- HTTP or HTTPS ([HTTP2 ](https://github.com/nodejs/http2 ) will be added once ready)
- URL rewriting
- Local rewrites for quick experimentation (e.g. from `/img/logo.svg` to `/img/new-logo.svg` )
- Rewrite to remote resources (e.g. from `/api/*` to `https://example-api.pl/api/$1` ). *Note: ignores remote server's CORS policy, which during development is typically what you want* .
2017-05-14 23:06:20 +01:00
- Optimisal caching by default.
- Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
2017-03-23 23:17:14 +00:00
- Configurable log output, compatible with [Goaccess, Logstalgia and glTail ](https://github.com/lwsjs/local-web-server/blob/master/doc/visualisation.md )
- Configurable CORS rules. All origins allowed by default.
2016-06-20 20:32:32 +01:00
2017-05-14 23:06:20 +01:00
**Links to demoes and how-tos**
2016-06-20 20:32:32 +01:00
2017-03-23 23:17:14 +00:00
Things you can build:
2016-07-16 09:59:11 +01:00
2017-03-23 23:17:14 +00:00
- Simple static website
- Single Page Application
- Works well with React, Angular or vanilla JS.
- Real or mock web services
- e.g. a RESTful API or microservice
- Mocks are defined with config (static), or code (dynamic).
- Websocket server
2016-07-16 09:59:11 +01:00
2015-11-15 21:15:25 +00:00
## Synopsis
2017-03-23 23:17:14 +00:00
2016-06-20 20:32:32 +01:00
local-web-server is a command-line tool. To serve the current directory, run `ws` .
2015-11-27 09:31:28 +00:00
2015-11-27 09:40:53 +00:00
< pre > < code > $ ws --help
2015-11-27 09:31:28 +00:00
< strong > local-web-server< / strong >
2017-03-23 23:17:14 +00:00
A convenient local web server to support productive, full-stack Javascript
development.
2015-11-27 09:31:28 +00:00
2015-11-27 09:36:46 +00:00
< strong > Synopsis< / strong >
2015-11-27 09:31:28 +00:00
2017-03-23 23:26:15 +00:00
$ ws [--verbose] [--config-file file] [< server options> ] [< middleware options> ]
2015-11-27 09:31:28 +00:00
$ ws --config
$ ws --help
2017-03-23 23:17:14 +00:00
$ ws --version
< strong > General< / strong >
-h, --help Print these usage instructions.
--config Print the active config.
-c, --config-file file Config filename to use, defaults to "lws.config.js".
-v, --verbose Verbose output.
--version Print the version number.
2015-11-27 09:31:28 +00:00
2015-11-27 09:36:46 +00:00
< strong > Server< / strong >
2015-11-27 09:31:28 +00:00
2017-03-23 23:17:14 +00:00
-p, --port number Web server port.
--hostname string The hostname (or IP address) to listen on. Defaults to 0.0.0.0.
--stack feature ... Feature stack.
--key file SSL key. Supply along with --cert to launch a https server.
--cert file SSL cert. Supply along with --key to launch a https server.
--https Enable HTTPS using a built-in key and cert, registered to the domain
127.0.0.1.
2016-06-20 22:57:34 +01:00
< strong > Middleware< / strong >
2017-03-23 23:17:14 +00:00
-f, --log.format string If a format is supplied an access log is written to stdout. If not, a dynamic
statistics view is displayed. Use a preset ('none', 'dev','combined',
'short', 'tiny', 'stats', or 'logstalgia') or supply a custom format (e.g.
':method -> :url').
--cors.origin Access-Control-Allow-Origin value. Default is request Origin header.
--cors.allow-methods Access-Control-Allow-Methods value. Default is
"GET,HEAD,PUT,POST,DELETE,PATCH"
2016-06-20 22:57:34 +01:00
-r, --rewrite expression ... 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'.
2015-11-27 09:31:28 +00:00
-b, --forbid path ... A list of forbidden routes.
2017-03-23 23:17:14 +00:00
-n, --no-cache Disable etag-based caching - forces loading from disk each request.
-z, --compress Serve gzip-compressed resources, where applicable.
--compress.threshold number Minimum response size in bytes to apply compression. Defaults to 1024 bytes.
--spa file Path to a Single Page App, e.g. app.html.
--spa.asset-test RegExp A regular expression to identify an asset file. Defaults to "\.".
2016-06-20 22:57:34 +01:00
-d, --directory path Root directory, defaults to the current directory.
2017-03-23 23:17:14 +00:00
--static.maxage number Browser cache max-age in milliseconds.
--static.defer If true, serves after `yield next` , allowing any downstream middleware to
respond first.
--static.index path Default file name, defaults to `index.html` .
--index.root path Index root directory, defaults to --directory or the current directory.
--index.hidden Show hidden files.
--index.view name Display mode, either `tiles` or `details` . Defaults to tiles.
2015-11-27 09:31:28 +00:00
2017-03-23 21:42:21 +00:00
Project home: https://github.com/lwsjs/local-web-server
2015-11-27 09:31:28 +00:00
< / code > < / pre >
2015-02-01 14:04:17 +00:00
## Install
2013-06-04 14:23:50 +01:00
```sh
$ npm install -g local-web-server
```
2015-11-08 22:09:07 +00:00
* * *
2017-03-13 23:44:11 +00:00
© 2013-17 Lloyd Brookes < 75pound @gmail .com > . Documented by [jsdoc-to-markdown ](https://github.com/jsdoc2md/jsdoc-to-markdown ).