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.

128 lines
3.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 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. # local-web-server
  7. A simple web-server for productive front-end development.
  8. **Requires node v4.0.0 or higher**.
  9. ## Synopsis
  10. Serve a directory on the default port:
  11. ```sh
  12. $ ws
  13. serving at http://localhost:8000
  14. ```
  15. Blacklist certain paths, for example config files:
  16. ```sh
  17. $ ws --forbid .json .yml
  18. serving at http://localhost:8000
  19. ```
  20. Reduce bandwidth with gzip compression:
  21. ```sh
  22. $ ws --compress
  23. ```
  24. Specify a Single Page Application:
  25. ```sh
  26. $ ws --spa index.html
  27. ```
  28. ## Install
  29. Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
  30. ```sh
  31. $ npm install -g local-web-server
  32. ```
  33. ## Distribute with your project
  34. ```sh
  35. $ npm install local-web-server --save-dev
  36. ```
  37. Then add an `start` script to your `package.json` (the standard npm approach):
  38. ```json
  39. {
  40. "name": "my-web-app",
  41. "version": "1.0.0",
  42. "scripts": {
  43. "start": "ws"
  44. }
  45. }
  46. ```
  47. This simplifies a rather specific-looking instruction set like:
  48. ```sh
  49. $ npm install
  50. $ npm install -g local-web-server
  51. $ ws
  52. ```
  53. to the following, server implementation and launch details abstracted away:
  54. ```sh
  55. $ npm install
  56. $ npm start
  57. ```
  58. ## Storing default options
  59. To store per-project options, saving you the hassle of inputting them everytime, store them in the `local-web-server` property of your project's `package.json`:
  60. ```json
  61. {
  62. "name": "my-project",
  63. "version": "0.11.8",
  64. "local-web-server":{
  65. "port": 8100
  66. }
  67. }
  68. ```
  69. Or in a `.local-web-server.json` file stored in the directory you want to serve (typically the root folder of your site):
  70. ```json
  71. {
  72. "port": 8100,
  73. "log-format": "tiny"
  74. }
  75. ```
  76. Or store global defaults in a `.local-web-server.json` file in your home directory.
  77. ```json
  78. {
  79. "port": 3000,
  80. "refresh-rate": 1000
  81. }
  82. ```
  83. All stored defaults are overriden by options supplied at the command line.
  84. To view your stored defaults, run:
  85. ```sh
  86. $ ws --config
  87. ```
  88. ## mime-types
  89. You can set additional mime-type/extension mappings, or override the defaults by setting a `mime` value in your local config. This value is passed directly to [mime.define()](https://github.com/broofa/node-mime#mimedefine). Example:
  90. ```json
  91. {
  92. "mime": {
  93. "text/plain": [ "php", "pl" ]
  94. }
  95. }
  96. ```
  97. ## Log Visualisation
  98. Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation).
  99. ## API Reference
  100. {{>main}}
  101. * * *
  102. &copy; 2015 Lloyd Brookes <75pound@gmail.com>