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.

111 lines
5.6 KiB

9 years ago
11 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
12 years ago
  1. [![view on npm](http://img.shields.io/npm/v/local-web-server.svg)](https://www.npmjs.org/package/local-web-server)
  2. [![npm module downloads](http://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. [![Dependency Status](https://david-dm.org/lwsjs/local-web-server.svg)](https://david-dm.org/lwsjs/local-web-server)
  5. [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
  6. [![Join the chat at https://gitter.im/lwsjs/local-web-server](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/lwsjs/local-web-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
  7. ***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.***
  8. # local-web-server
  9. A convenient local web server to support productive, full-stack Javascript development. Built on [lws](https://github.com/lwsjs/lws).
  10. **Features**
  11. - Lightweight
  12. - http/https ([http2](https://github.com/nodejs/http2) will be added once ready)
  13. - Rewrite routes to local or remote resources
  14. - Url rewriting
  15. - Proxy certain routes to a remote server (e.g. an existing API). Avoids CORS pain when consuming remote services.
  16. - Configurable by command-line options, stored config or both
  17. - Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
  18. - Configurable log output, compatible with [Goaccess, Logstalgia and glTail](https://github.com/lwsjs/local-web-server/blob/master/doc/visualisation.md)
  19. - Configurable CORS rules. All origins allowed by default.
  20. **Use cases**
  21. Things you can build:
  22. - Simple static website
  23. - Single Page Application
  24. - Works well with React, Angular or vanilla JS.
  25. - Real or mock web services
  26. - e.g. a RESTful API or microservice
  27. - Mocks are defined with config (static), or code (dynamic).
  28. - Websocket server
  29. ## Synopsis
  30. local-web-server is a command-line tool. To serve the current directory, run `ws`.
  31. <pre><code>$ ws --help
  32. <strong>local-web-server</strong>
  33. A convenient local web server to support productive, full-stack Javascript
  34. development.
  35. <strong>Synopsis</strong>
  36. $ ws [--verbose] [--config-file file] [<server options>] [<middleware options>]
  37. $ ws --config
  38. $ ws --help
  39. $ ws --version
  40. <strong>General</strong>
  41. -h, --help Print these usage instructions.
  42. --config Print the active config.
  43. -c, --config-file file Config filename to use, defaults to "lws.config.js".
  44. -v, --verbose Verbose output.
  45. --version Print the version number.
  46. <strong>Server</strong>
  47. -p, --port number Web server port.
  48. --hostname string The hostname (or IP address) to listen on. Defaults to 0.0.0.0.
  49. --stack feature ... Feature stack.
  50. --key file SSL key. Supply along with --cert to launch a https server.
  51. --cert file SSL cert. Supply along with --key to launch a https server.
  52. --https Enable HTTPS using a built-in key and cert, registered to the domain
  53. 127.0.0.1.
  54. <strong>Middleware</strong>
  55. -f, --log.format string If a format is supplied an access log is written to stdout. If not, a dynamic
  56. statistics view is displayed. Use a preset ('none', 'dev','combined',
  57. 'short', 'tiny', 'stats', or 'logstalgia') or supply a custom format (e.g.
  58. ':method -> :url').
  59. --cors.origin Access-Control-Allow-Origin value. Default is request Origin header.
  60. --cors.allow-methods Access-Control-Allow-Methods value. Default is
  61. "GET,HEAD,PUT,POST,DELETE,PATCH"
  62. -r, --rewrite expression ... A list of URL rewrite rules. For each rule, separate the 'from' and 'to'
  63. routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from ->
  64. /to'.
  65. -b, --forbid path ... A list of forbidden routes.
  66. -n, --no-cache Disable etag-based caching - forces loading from disk each request.
  67. -z, --compress Serve gzip-compressed resources, where applicable.
  68. --compress.threshold number Minimum response size in bytes to apply compression. Defaults to 1024 bytes.
  69. --spa file Path to a Single Page App, e.g. app.html.
  70. --spa.asset-test RegExp A regular expression to identify an asset file. Defaults to "\.".
  71. -d, --directory path Root directory, defaults to the current directory.
  72. --static.maxage number Browser cache max-age in milliseconds.
  73. --static.defer If true, serves after `yield next`, allowing any downstream middleware to
  74. respond first.
  75. --static.index path Default file name, defaults to `index.html`.
  76. --index.root path Index root directory, defaults to --directory or the current directory.
  77. --index.hidden Show hidden files.
  78. --index.view name Display mode, either `tiles` or `details`. Defaults to tiles.
  79. Project home: https://github.com/lwsjs/local-web-server
  80. </code></pre>
  81. ## Install
  82. ```sh
  83. $ npm install -g local-web-server
  84. ```
  85. * * *
  86. &copy; 2013-17 Lloyd Brookes <75pound@gmail.com>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).