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.

164 lines
4.0 KiB

9 years ago
10 years ago
10 years ago
9 years ago
11 years ago
10 years ago
9 years ago
9 years ago
10 years ago
11 years ago
9 years ago
11 years ago
9 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
10 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 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. # local-web-server
  7. A static web-server for productive front-end development.
  8. **Requires node v4.0.0 or higher**.
  9. ## Synopsis
  10. From the folder you wish to serve, run:
  11. ```sh
  12. $ ws
  13. serving at http://localhost:8000
  14. ```
  15. If you wish to serve a different directory, run:
  16. ```sh
  17. $ ws -d ~/mysite/
  18. serving /Users/Lloyd/mysite at http://localhost:8000
  19. ```
  20. If you wish to override the default port (8000), use `--port` or `-p`:
  21. ```sh
  22. $ ws --port 9000
  23. serving at http://localhost:9000
  24. ```
  25. To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
  26. ```sh
  27. $ ws --compress
  28. ```
  29. ## Install
  30. Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
  31. ### Globally
  32. ```sh
  33. $ npm install -g local-web-server
  34. ```
  35. ### Bundled with your project
  36. ```sh
  37. $ npm install local-web-server --save-dev
  38. ```
  39. Then add an `start` script to your `package.json` (the standard npm approach):
  40. ```json
  41. {
  42. "name": "my-web-app",
  43. "version": "1.0.0",
  44. "scripts": {
  45. "start": "ws"
  46. }
  47. }
  48. ```
  49. This simplifies a rather specific-looking instruction set like:
  50. ```sh
  51. $ npm install
  52. $ npm install -g local-web-server
  53. $ ws
  54. ```
  55. to the following, server implementation and launch details abstracted away:
  56. ```sh
  57. $ npm install
  58. $ npm start
  59. ```
  60. ### Logging
  61. Passing a value to `--log-format` will write an access log to `stdout`.
  62. Either use a built-in [morgan](https://github.com/expressjs/morgan) logger preset:
  63. ```sh
  64. $ ws --log-format short
  65. ```
  66. Or a custom [morgan](https://github.com/expressjs/morgan) log format:
  67. ```sh
  68. $ ws -f ':method -> :url'
  69. ```
  70. Or silence:
  71. ```sh
  72. $ ws -f none
  73. ```
  74. ## Storing default options
  75. 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`:
  76. ```json
  77. {
  78. "name": "my-project",
  79. "version": "0.11.8",
  80. "local-web-server":{
  81. "port": 8100
  82. }
  83. }
  84. ```
  85. Or in a `.local-web-server.json` file stored in the directory you want to serve (typically the root folder of your site):
  86. ```json
  87. {
  88. "port": 8100,
  89. "log-format": "tiny"
  90. }
  91. ```
  92. Or store global defaults in a `.local-web-server.json` file in your home directory.
  93. ```json
  94. {
  95. "port": 3000,
  96. "refresh-rate": 1000
  97. }
  98. ```
  99. All stored defaults are overriden by options supplied at the command line.
  100. To view your stored defaults, run:
  101. ```sh
  102. $ ws --config
  103. ```
  104. ## mime-types
  105. 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:
  106. ```json
  107. {
  108. "mime": {
  109. "text/plain": [ "php", "pl" ]
  110. }
  111. }
  112. ```
  113. ## Log Visualisation
  114. Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation).
  115. # API Reference
  116. <a name="module_local-web-server"></a>
  117. ## local-web-server
  118. <a name="exp_module_local-web-server--localWebServer"></a>
  119. ### localWebServer([options]) ⏏
  120. Returns a Koa application
  121. **Kind**: Exported function
  122. | Param | Type | Description |
  123. | --- | --- | --- |
  124. | [options] | <code>object</code> | options |
  125. | [options.blacklist] | <code>Array.&lt;regexp&gt;</code> | a list of forbidden routes. |
  126. **Example**
  127. ```js
  128. const localWebServer = require('local-web-server')
  129. ```
  130. * * *
  131. &copy; 2015 Lloyd Brookes <75pound@gmail.com>