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.

114 lines
5.9 KiB

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