You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
4.9 KiB

7 years ago
7 years ago
10 years ago
7 years ago
9 years ago
9 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
9 years ago
9 years ago
11 years ago
7 years ago
11 years ago
7 years ago
11 years ago
  1. [![view on npm](https://img.shields.io/npm/v/local-web-server.svg)](https://www.npmjs.org/package/local-web-server)
  2. [![npm module downloads](https://img.shields.io/npm/dt/local-web-server.svg)](https://www.npmjs.org/package/local-web-server)
  3. [![Build Status](https://travis-ci.org/lwsjs/local-web-server.svg?branch=master)](https://travis-ci.org/lwsjs/local-web-server)
  4. [![Coverage Status](https://coveralls.io/repos/github/lwsjs/local-web-server/badge.svg?branch=master)](https://coveralls.io/github/lwsjs/local-web-server?branch=master)
  5. [![Dependency Status](https://badgen.net/david/dep/lwsjs/local-web-server)](https://david-dm.org/lwsjs/local-web-server)
  6. [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
  7. **Requires node v8 or above. Upgraders, please read the [release notes](https://github.com/lwsjs/local-web-server/releases)**.
  8. # local-web-server
  9. The modular web server for productive full-stack development.
  10. Use this tool to:
  11. * Build any flavour of web application (static site, dynamic site with client or server-rendered content, Single Page App, Progessive Web App, Angular or React app etc.)
  12. * Prototype any CORS-enabled back-end service (e.g. RESTful HTTP API or Microservice using websockets, Server Sent Events etc.)
  13. * Monitor activity, analyse performance, experiment with caching strategies etc.
  14. * Build your own, personalised CLI web server tool
  15. Features:
  16. * Modular, extensible and easy to personalise. Create, share and consume only plugins which match your requirements.
  17. * Powerful, extensible command-line interface (add your own commands and options)
  18. * HTTP, HTTPS and HTTP2 support (HTTP2 requires node v8.4.0 or above)
  19. * URL Rewriting to local or remote destinations
  20. * Single Page Application support
  21. * Response mocking
  22. * Configurable access log
  23. * Route blacklisting
  24. * HTTP Conditional and Range request support
  25. * Gzip response compression, HTTP Basic Authentication and much more
  26. ## Synopsis
  27. 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)).
  28. ### Static web site
  29. 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.
  30. ```sh
  31. $ ws
  32. Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
  33. ```
  34. ### Single Page Application
  35. Serving a Single Page Application (an app with client-side routing, e.g. a React or Angular app) is as trivial as specifying the name of your single page:
  36. ```sh
  37. $ ws --spa index.html
  38. Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
  39. ```
  40. By default, requests for typical SPA paths (e.g. `/user/1`, `/login`) return `404 Not Found` as a file at that location does not exist. By marking `index.html` as the SPA you create this rule:
  41. *If a static file is requested (e.g. `/css/style.css`) then serve it, if not (e.g. `/login`) then serve the specified SPA and handle the route client-side.*
  42. [Read more](https://github.com/lwsjs/local-web-server/wiki/How-to-serve-a-Single-Page-Application-(SPA)).
  43. ### URL rewriting and proxied requests
  44. 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/`:
  45. ```sh
  46. $ ws --rewrite '/api/* -> https://internal-service.local/api/$1'
  47. Serving at http://mbp.local:8000, http://127.0.0.1:8000, http://192.168.0.100:8000
  48. ```
  49. ### HTTPS
  50. Launching a secure server is as simple as setting the `--https` flag. [See the wiki](https://github.com/lwsjs/local-web-server/wiki) for further configuration options and a guide on how to get the "green padlock" in your browser.
  51. ```sh
  52. $ ws --https
  53. Serving at https://mbp.local:8000, https://127.0.0.1:8000, https://192.168.0.100:8000
  54. ```
  55. ### HTTP2
  56. Uses node's built-in HTTP2 support. HTTP2 servers are always secure using local-web-server's built-in SSL certificates (by default) or those supplied by `--cert`, `--key` or `--pfx`. [See the wiki](https://github.com/lwsjs/local-web-server/wiki) for further info about HTTPS options and a guide on how to get the "green padlock" in your browser.
  57. ```sh
  58. $ ws --http2
  59. Serving at https://mbp.local:8000, https://127.0.0.1:8000, https://192.168.0.100:8000
  60. ```
  61. ## Further Documentation
  62. [See the wiki for plenty more documentation and tutorials](https://github.com/lwsjs/local-web-server/wiki).
  63. ## Install
  64. **Requires node v8 or above**. Install the [previous release](https://github.com/lwsjs/local-web-server/tree/v1.x) for node >= v4.0.0.
  65. ```sh
  66. $ npm install -g local-web-server
  67. ```
  68. * * *
  69. &copy; 2013-19 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).