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)
[](https://travis-ci.org/75lb/local-web-server)
2014-05-08 15:05:06 +02:00
[](https://david-dm.org/75lb/local-web-server)
2015-10-30 11:31:59 +00:00
[](https://github.com/feross/standard)
2015-12-15 22:33:11 +00:00
[](https://gitter.im/75lb/local-web-server?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2014-01-24 19:49:11 +01:00
2015-11-30 17:52:46 +00:00
***Requires node v4.0.0 or higher. Install the [previous release ](https://github.com/75lb/local-web-server/tree/prev ) for older node support.***
2015-11-20 09:52:51 +00:00
2015-02-01 14:04:17 +00:00
# local-web-server
2016-07-16 09:59:11 +01:00
At its core, local-web-server is an application shell for building a specialised command-line web server to support productive Web Platform engineers. It comes bundled with a middleware stack covering common requirements but any arbitrary stack can be specified from the command line or config.
2015-11-26 21:12:49 +00:00
2016-07-16 09:59:11 +01:00
Being an npm module, it is trivial is bundle and distribute/deploy with your web application.
2016-06-20 20:32:32 +01:00
2016-07-16 09:59:11 +01:00
**Typically used for building:**
2016-06-20 20:32:32 +01:00
2016-07-16 09:59:11 +01:00
* Simple static site
* Single Page Application
* Works well with React, Angular or vanilla JS.
2016-06-20 20:32:32 +01:00
2016-07-16 09:59:11 +01:00
**Backend scenarios covered:**
2016-06-20 20:32:32 +01:00
2016-07-16 09:59:11 +01:00
* Existing API
* Mock API
* Websocket server
**Server options**
* HTTP or HTTPS server
* HTTPS is strictly required by some modern techs (ServiceWorker, Media Capture and Streams etc.)
* Configurable middleware stack
* Use any combination of built-in and custom middleware
* specify options (for command line or config)
* Accepts Koa v1 or 2 middleware
**Built-in Middleware stack**
2016-06-20 20:32:32 +01:00
* Rewrite routes to local or remote resources
* Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
2015-11-26 21:12:49 +00:00
* Configurable log output, compatible with [Goaccess, Logstalgia and glTail ](https://github.com/75lb/local-web-server/blob/master/doc/visualisation.md )
2016-06-20 20:32:32 +01:00
* Proxy server
* Map local routes to remote servers. Removes CORS pain when consuming remote services.
* Back-end service mocking
* Prototype a web service, microservice, REST API etc.
* Mocks are defined with config (static), or code (dynamic).
2015-11-26 21:12:49 +00:00
* CORS-friendly, all origins allowed by default.
2013-06-04 14:23:50 +01:00
2016-07-16 09:59:11 +01:00
**Personalised stack**
2015-11-15 21:15:25 +00:00
## Synopsis
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 >
A simple web-server for productive front-end development.
2015-11-27 09:36:46 +00:00
< strong > Synopsis< / strong >
2015-11-27 09:31:28 +00:00
2016-06-20 22:57:34 +01:00
$ ws [--verbose] [< server options > ] [< middleware options > ]
2015-11-27 09:31:28 +00:00
$ ws --config
$ ws --help
2015-11-27 09:36:46 +00:00
< strong > Server< / strong >
2015-11-27 09:31:28 +00:00
2016-06-20 22:57:34 +01:00
-p, --port number Web server port.
--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.
< strong > Middleware< / strong >
-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.
2015-11-27 09:36:46 +00:00
-n, --no-cache Disable etag-based caching -forces loading from disk each request.
2016-06-20 22:57:34 +01:00
-c, --compress Serve gzip-compressed resources, where applicable.
2016-07-01 20:53:10 +01:00
-f, --log.format string If a format is supplied an access log is written to stdout. If not, a dynamic
2016-06-20 22:57:34 +01:00
statistics view is displayed. Use a preset ('none', 'dev','combined',
'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method ->
:url').
-s, --spa file Path to a Single Page App, e.g. app.html.
-d, --directory path Root directory, defaults to the current directory.
2015-11-27 09:31:28 +00:00
2015-11-27 09:36:46 +00:00
< strong > Misc< / strong >
2015-11-27 09:31:28 +00:00
-h, --help Print these usage instructions.
--config Print the stored config.
Project home: https://github.com/75lb/local-web-server
< / code > < / pre >
2015-11-19 10:01:04 +00:00
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
* * *
2016-03-10 10:58:52 +00:00
© 2013-16 Lloyd Brookes < 75pound @gmail .com > . Documented by [jsdoc-to-markdown ](https://github.com/jsdoc2md/jsdoc-to-markdown ).