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.

121 lines
5.4 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
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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
11 years ago
12 years ago
9 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. An application shell for building a simple, command-line web server for productive web development.
  10. It is trivial is bundle and deploy with your project. Also deploys to heroku well for demo projects.
  11. It comes with some middleware built-in, which you need not use but will get you up and running for the following use cases:
  12. * Static or Single Page Application front-end development where you have
  13. * No backend, an existing remote API or need to mock-up an API.
  14. Application Shell
  15. * HTTP or HTTPS server
  16. * HTTPS is strictly required by some modern techs (ServiceWorker, Media Capture and Streams etc.)
  17. * Add your middleware
  18. * Use any combination of built-in and custom middleware
  19. * specify options (for command line or config)
  20. * Accepts Koa v1 or 2 middleware
  21. * Bundle with your front-end project
  22. * Configuration is via json file or command-line (latter taking precedence)
  23. * Outputs a dynamic statistics view to the terminal
  24. Built-in Middleware (all optional)
  25. * Rewrite routes to local or remote resources
  26. * Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
  27. * Configurable log output, compatible with [Goaccess, Logstalgia and glTail](https://github.com/75lb/local-web-server/blob/master/doc/visualisation.md)
  28. * Proxy server
  29. * Map local routes to remote servers. Removes CORS pain when consuming remote services.
  30. * Back-end service mocking
  31. * Prototype a web service, microservice, REST API etc.
  32. * Mocks are defined with config (static), or code (dynamic).
  33. * CORS-friendly, all origins allowed by default.
  34. ## Synopsis
  35. local-web-server is a command-line tool. To serve the current directory, run `ws`.
  36. <pre><code>$ ws --help
  37. <strong>local-web-server</strong>
  38. A simple web-server for productive front-end development.
  39. <strong>Synopsis</strong>
  40. $ ws [--verbose] [<server options>] [<middleware options>]
  41. $ ws --config
  42. $ ws --help
  43. <strong>Server</strong>
  44. -p, --port number Web server port.
  45. --key file SSL key. Supply along with --cert to launch a https server.
  46. --cert file SSL cert. Supply along with --key to launch a https server.
  47. --https Enable HTTPS using a built-in key and cert, registered to the domain
  48. 127.0.0.1.
  49. <strong>Middleware</strong>
  50. -r, --rewrite expression ... A list of URL rewrite rules. For each rule, separate the 'from' and 'to'
  51. routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from ->
  52. /to'.
  53. -b, --forbid path ... A list of forbidden routes.
  54. -n, --no-cache Disable etag-based caching -forces loading from disk each request.
  55. -c, --compress Serve gzip-compressed resources, where applicable.
  56. -f, --log-format string If a format is supplied an access log is written to stdout. If not, a dynamic
  57. statistics view is displayed. Use a preset ('none', 'dev','combined',
  58. 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method ->
  59. :url').
  60. -s, --spa file Path to a Single Page App, e.g. app.html.
  61. -d, --directory path Root directory, defaults to the current directory.
  62. <strong>Misc</strong>
  63. -h, --help Print these usage instructions.
  64. --config Print the stored config.
  65. Project home: https://github.com/75lb/local-web-server
  66. </code></pre>
  67. ## Examples
  68. For the examples below, we assume we're in a project directory looking like this:
  69. ```sh
  70. .
  71. ├── css
  72. │   └── style.css
  73. ├── index.html
  74. └── package.json
  75. ```
  76. All paths/routes are specified using [express syntax](http://expressjs.com/guide/routing.html#route-paths). To run the example projects linked below, clone the project, move into the example directory specified, run `ws`.
  77. ### Static site
  78. Fire up your static site on the default port:
  79. ```sh
  80. $ ws
  81. serving at http://localhost:8000
  82. ```
  83. [Example](https://github.com/75lb/local-web-server/tree/master/example/simple).
  84. ## Install
  85. Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
  86. ```sh
  87. $ npm install -g local-web-server
  88. ```
  89. * * *
  90. &copy; 2013-16 Lloyd Brookes <75pound@gmail.com>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).