readme.. fix test
This commit is contained in:
114
README.md
114
README.md
@ -5,96 +5,102 @@
|
|||||||
[](https://github.com/feross/standard)
|
[](https://github.com/feross/standard)
|
||||||
[](https://gitter.im/lwsjs/local-web-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/lwsjs/local-web-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
***Requires node v7.6 or higher. Install the [previous release](https://github.com/lwsjs/local-web-server/tree/prev) for older node support.***
|
***Requires node v7.6 or higher. Install the [previous release](https://github.com/lwsjs/local-web-server/tree/v1.x) for older node support. Documentation still WIP.***
|
||||||
|
|
||||||
# local-web-server
|
# local-web-server
|
||||||
At its core, local-web-server is an application shell for building a specialised command-line web server to support productive Web Platform engineers. When combined with built-in and custom features it's in intended to by a powerful tool in helping build and debug Web applications. It comes bundled with a middleware stack covering common requirements but any arbitrary stack can be specified from the command line or config.
|
|
||||||
|
|
||||||
Being an npm module, it is trivial is bundle and distribute/deploy with your web application.
|
A convenient local web server to support productive, full-stack Javascript development. Built on [lws](https://github.com/lwsjs/lws).
|
||||||
|
|
||||||
**Typically used for building:**
|
**Features**
|
||||||
|
|
||||||
* Simple static site
|
- Lightweight
|
||||||
* Single Page Application
|
- http/https ([http2](https://github.com/nodejs/http2) will be added once ready)
|
||||||
* Works well with React, Angular or vanilla JS.
|
- Rewrite routes to local or remote resources
|
||||||
|
- Url rewriting
|
||||||
|
- Proxy certain routes to a remote server (e.g. an existing API). Avoids CORS pain when consuming remote services.
|
||||||
|
- Configurable by command-line options, stored config or both
|
||||||
|
- Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
|
||||||
|
- 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.
|
||||||
|
|
||||||
**Backend scenarios covered:**
|
**Use cases**
|
||||||
|
|
||||||
* Existing API
|
Things you can build:
|
||||||
* 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**
|
|
||||||
|
|
||||||
* 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)
|
|
||||||
* Configurable log output, compatible with [Goaccess, Logstalgia and glTail](https://github.com/lwsjs/local-web-server/blob/master/doc/visualisation.md)
|
|
||||||
* 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).
|
|
||||||
* CORS-friendly, all origins allowed by default.
|
|
||||||
|
|
||||||
**Personalised stack**
|
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
local-web-server is a command-line tool. To serve the current directory, run `ws`.
|
local-web-server is a command-line tool. To serve the current directory, run `ws`.
|
||||||
|
|
||||||
<pre><code>$ ws --help
|
<pre><code>$ ws --help
|
||||||
|
|
||||||
<strong>local-web-server</strong>
|
<strong>local-web-server</strong>
|
||||||
|
|
||||||
A simple web-server for productive front-end development.
|
A convenient local web server to support productive, full-stack Javascript
|
||||||
|
development.
|
||||||
|
|
||||||
<strong>Synopsis</strong>
|
<strong>Synopsis</strong>
|
||||||
|
|
||||||
$ ws [--verbose] [<server options>] [<middleware options>]
|
$ ws [--verbose] [--config-file file] [<server options>] [<middleware options>]
|
||||||
$ ws --config
|
$ ws --config
|
||||||
$ ws --help
|
$ ws --help
|
||||||
|
$ 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.
|
||||||
|
|
||||||
<strong>Server</strong>
|
<strong>Server</strong>
|
||||||
|
|
||||||
-p, --port number Web server port.
|
-p, --port number Web server port.
|
||||||
--key file SSL key. Supply along with --cert to launch a https server.
|
--hostname string The hostname (or IP address) to listen on. Defaults to 0.0.0.0.
|
||||||
--cert file SSL cert. Supply along with --key to launch a https server.
|
--stack feature ... Feature stack.
|
||||||
--https Enable HTTPS using a built-in key and cert, registered to the domain
|
--key file SSL key. Supply along with --cert to launch a https server.
|
||||||
127.0.0.1.
|
--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>
|
<strong>Middleware</strong>
|
||||||
|
|
||||||
|
-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"
|
||||||
-r, --rewrite expression ... A list of URL rewrite rules. For each rule, separate the 'from' and 'to'
|
-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 ->
|
routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from ->
|
||||||
/to'.
|
/to'.
|
||||||
-b, --forbid path ... A list of forbidden routes.
|
-b, --forbid path ... A list of forbidden routes.
|
||||||
-n, --no-cache Disable etag-based caching -forces loading from disk each request.
|
-n, --no-cache Disable etag-based caching - forces loading from disk each request.
|
||||||
-c, --compress Serve gzip-compressed resources, where applicable.
|
-z, --compress Serve gzip-compressed resources, where applicable.
|
||||||
-f, --log.format string If a format is supplied an access log is written to stdout. If not, a dynamic
|
--compress.threshold number Minimum response size in bytes to apply compression. Defaults to 1024 bytes.
|
||||||
statistics view is displayed. Use a preset ('none', 'dev','combined',
|
--spa file Path to a Single Page App, e.g. app.html.
|
||||||
'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method ->
|
--spa.asset-test RegExp A regular expression to identify an asset file. Defaults to "\.".
|
||||||
:url').
|
|
||||||
-s, --spa file Path to a Single Page App, e.g. app.html.
|
|
||||||
-d, --directory path Root directory, defaults to the current directory.
|
-d, --directory path Root directory, defaults to the current directory.
|
||||||
|
--static.maxage number Browser cache max-age in milliseconds.
|
||||||
<strong>Misc</strong>
|
--static.defer If true, serves after `yield next`, allowing any downstream middleware to
|
||||||
|
respond first.
|
||||||
-h, --help Print these usage instructions.
|
--static.index path Default file name, defaults to `index.html`.
|
||||||
--config Print the stored config.
|
--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.
|
||||||
|
|
||||||
Project home: https://github.com/lwsjs/local-web-server
|
Project home: https://github.com/lwsjs/local-web-server
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
"lws-compress": "^0.1.0",
|
"lws-compress": "^0.1.0",
|
||||||
"lws-conditional-get": "^0.1.0",
|
"lws-conditional-get": "^0.1.0",
|
||||||
"lws-cors": "^0.1.0",
|
"lws-cors": "^0.1.0",
|
||||||
"lws-index": "^0.1.0",
|
"lws-index": "^0.1.1",
|
||||||
"lws-json": "^0.1.0",
|
"lws-json": "^0.1.0",
|
||||||
"lws-log": "^0.1.1",
|
"lws-log": "^0.1.1",
|
||||||
"lws-mime": "^0.1.0",
|
"lws-mime": "^0.1.0",
|
||||||
@ -50,7 +50,7 @@
|
|||||||
"lws-rewrite": "^0.1.0",
|
"lws-rewrite": "^0.1.0",
|
||||||
"lws-spa": "^0.1.0",
|
"lws-spa": "^0.1.0",
|
||||||
"lws-static": "^0.1.1",
|
"lws-static": "^0.1.1",
|
||||||
"lws": "^1.0.0-pre.3"
|
"lws": "^1.0.0-pre.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"test-runner": "^0.3.0"
|
"test-runner": "^0.3.0"
|
||||||
|
@ -10,7 +10,7 @@ runner.test('basic', async function () {
|
|||||||
const port = 9000 + this.index
|
const port = 9000 + this.index
|
||||||
const localWebServer = new LocalWebServer({
|
const localWebServer = new LocalWebServer({
|
||||||
port: port,
|
port: port,
|
||||||
'static.root': 'test/fixture',
|
directory: 'test/fixture',
|
||||||
'log.format': 'none'
|
'log.format': 'none'
|
||||||
})
|
})
|
||||||
localWebServer.start()
|
localWebServer.start()
|
||||||
|
Reference in New Issue
Block a user