readme
This commit is contained in:
29
README.md
29
README.md
@ -14,8 +14,8 @@ The modular web server for productive full-stack development.
|
|||||||
Use this tool to:
|
Use this tool to:
|
||||||
|
|
||||||
* Build fast, modern web applications using any tech, framework or architecture.
|
* Build fast, modern web applications using any tech, framework or architecture.
|
||||||
* Prototype back-end services (RESTful HTTP API, Microservice, websocket server etc.)
|
* Prototype back-end services (RESTful HTTP API, Microservice, websocket server, Server Sent Events etc.)
|
||||||
* Monitor activity, analyse performance, compare caching strategies etc.
|
* Monitor activity, analyse performance, experiment with caching strategies etc.
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
|
||||||
@ -31,20 +31,41 @@ Features:
|
|||||||
|
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
This package installs the `ws` command-line tool (take a look at the [usage guide](https://github.com/lwsjs/local-web-server/wiki/CLI-usage)). The most simple use case is to run `ws` without any arguments - this will **host the current directory as a static web site**. Navigating to the server will render a directory listing or your `index.html`, if that file exists.
|
This package installs the `ws` command-line tool (take a look at the [usage guide](https://github.com/lwsjs/local-web-server/wiki/CLI-usage)).
|
||||||
|
|
||||||
|
#### Static web site
|
||||||
|
|
||||||
|
The most simple use case is to run `ws` without any arguments - this will **host the current directory as a static web site**. Navigating to the server will render a directory listing or your `index.html`, if that file exists.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ws
|
$ ws
|
||||||
Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
|
Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
Another common use case is to **proxy certain requests to a remote server** if, for example, you'd like to use data from a different environment. The following command would proxy requests with a URL beginning with `http://127.0.0.1:8000/api/` to `https://internal-service.local/api/`:
|
#### Single Page Application
|
||||||
|
|
||||||
|
Serving a Single Page Application is as trivial as specifying the name of your single page:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ ws --spa index.html
|
||||||
|
Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, requests for typical SPA paths (e.g. `/user/1`, `/login`) would return `404 Not Found` as a file at that locaiton does not exist. By marking `index.html` as the SPA you create this rule:
|
||||||
|
|
||||||
|
*If a static file at the requested path exists (e.g. `/css/style.css`) then serve it, if it does not (e.g. `/login`) then serve the specified SPA and handle the route client-side.*
|
||||||
|
|
||||||
|
#### URL rewriting and proxied requests
|
||||||
|
|
||||||
|
Another common use case is to **re-route certain requests to a remote server** if, for example, you'd like to use data from a different environment. The following command would proxy requests with a URL beginning with `http://127.0.0.1:8000/api/` to `https://internal-service.local/api/`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ws --rewrite '/api/* -> https://internal-service.local/api/$1'
|
$ ws --rewrite '/api/* -> https://internal-service.local/api/$1'
|
||||||
Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
|
Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Mock responses
|
||||||
|
|
||||||
Imagine the network is down or you're working offline, proxied requests to `https://internal-service.local/api/users/1` would fail. In this case, Mock Responses can fill the gap. Export your mock responses from a module.
|
Imagine the network is down or you're working offline, proxied requests to `https://internal-service.local/api/users/1` would fail. In this case, Mock Responses can fill the gap. Export your mock responses from a module.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
Reference in New Issue
Block a user