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.

105 lines
4.8 KiB

9 years ago
11 years ago
9 years ago
11 years ago
9 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
12 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/75lb/local-web-server.svg?branch=master)](https://travis-ci.org/75lb/local-web-server)
  4. [![Dependency Status](https://david-dm.org/75lb/local-web-server.svg)](https://david-dm.org/75lb/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/75lb/local-web-server](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/75lb/local-web-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
  7. ***Requires node v4.0.0 or higher. Install the [previous release](https://github.com/75lb/local-web-server/tree/prev) for older node support.***
  8. # local-web-server
  9. 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.
  10. Being an npm module, it is trivial is bundle and distribute/deploy with your web application.
  11. **Typically used for building:**
  12. * Simple static site
  13. * Single Page Application
  14. * Works well with React, Angular or vanilla JS.
  15. **Backend scenarios covered:**
  16. * Existing API
  17. * Mock API
  18. * Websocket server
  19. **Server options**
  20. * HTTP or HTTPS server
  21. * HTTPS is strictly required by some modern techs (ServiceWorker, Media Capture and Streams etc.)
  22. * Configurable middleware stack
  23. * Use any combination of built-in and custom middleware
  24. * specify options (for command line or config)
  25. * Accepts Koa v1 or 2 middleware
  26. **Built-in Middleware stack**
  27. * Rewrite routes to local or remote resources
  28. * Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
  29. * Configurable log output, compatible with [Goaccess, Logstalgia and glTail](https://github.com/75lb/local-web-server/blob/master/doc/visualisation.md)
  30. * Proxy server
  31. * Map local routes to remote servers. Removes CORS pain when consuming remote services.
  32. * Back-end service mocking
  33. * Prototype a web service, microservice, REST API etc.
  34. * Mocks are defined with config (static), or code (dynamic).
  35. * CORS-friendly, all origins allowed by default.
  36. **Personalised stack**
  37. ## Synopsis
  38. local-web-server is a command-line tool. To serve the current directory, run `ws`.
  39. <pre><code>$ ws --help
  40. <strong>local-web-server</strong>
  41. A simple web-server for productive front-end development.
  42. <strong>Synopsis</strong>
  43. $ ws [--verbose] [<server options>] [<middleware options>]
  44. $ ws --config
  45. $ ws --help
  46. <strong>Server</strong>
  47. -p, --port number Web server port.
  48. --key file SSL key. Supply along with --cert to launch a https server.
  49. --cert file SSL cert. Supply along with --key to launch a https server.
  50. --https Enable HTTPS using a built-in key and cert, registered to the domain
  51. 127.0.0.1.
  52. <strong>Middleware</strong>
  53. -r, --rewrite expression ... A list of URL rewrite rules. For each rule, separate the 'from' and 'to'
  54. routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from ->
  55. /to'.
  56. -b, --forbid path ... A list of forbidden routes.
  57. -n, --no-cache Disable etag-based caching -forces loading from disk each request.
  58. -c, --compress Serve gzip-compressed resources, where applicable.
  59. -f, --log.format string If a format is supplied an access log is written to stdout. If not, a dynamic
  60. statistics view is displayed. Use a preset ('none', 'dev','combined',
  61. 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method ->
  62. :url').
  63. -s, --spa file Path to a Single Page App, e.g. app.html.
  64. -d, --directory path Root directory, defaults to the current directory.
  65. <strong>Misc</strong>
  66. -h, --help Print these usage instructions.
  67. --config Print the stored config.
  68. Project home: https://github.com/75lb/local-web-server
  69. </code></pre>
  70. ## Install
  71. ```sh
  72. $ npm install -g local-web-server
  73. ```
  74. * * *
  75. &copy; 2013-17 Lloyd Brookes <75pound@gmail.com>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).