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.

194 lines
5.0 KiB

10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
12 years ago
10 years ago
10 years ago
10 years ago
12 years ago
10 years ago
12 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
10 years ago
12 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
12 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 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 per month](http://img.shields.io/npm/dm/local-web-server.svg)](https://www.npmjs.org/package/local-web-server)
  3. [![Dependency Status](https://david-dm.org/75lb/local-web-server.svg)](https://david-dm.org/75lb/local-web-server)
  4. ![Analytics](https://ga-beacon.appspot.com/UA-27725889-12/local-web-server/README.md?pixel)
  5. # local-web-server
  6. Fires up a simple, CORS-enabled, static web server on a given port. Use for local web development or file sharing (directory browsing enabled).
  7. ![local-web-server](http://75lb.github.io/local-web-server/ws.gif)
  8. ## Install
  9. Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
  10. ### Globally
  11. ```sh
  12. $ npm install -g local-web-server
  13. ```
  14. ### Bundled with your project
  15. ```sh
  16. $ npm install local-web-server --save-dev
  17. ```
  18. Then add an `start` script to your `package.json` (the standard npm approach):
  19. ```json
  20. {
  21. "name": "my-web-app",
  22. "version": "1.0.0",
  23. "scripts": {
  24. "start": "ws"
  25. }
  26. }
  27. ```
  28. This simplifies a rather specific-looking instruction set like:
  29. ```sh
  30. $ npm install
  31. $ npm install -g local-web-server
  32. $ ws
  33. ```
  34. to the following, server implementation and launch details abstracted away:
  35. ```sh
  36. $ npm install
  37. $ npm start
  38. ```
  39. ## Usage
  40. ```
  41. Usage
  42. $ ws <server options>
  43. $ ws --config
  44. $ ws --help
  45. Server
  46. -p, --port <number> Web server port
  47. -f, --log-format <string> If a format is supplied an access log is written to stdout. If not,
  48. a statistics view is displayed. Use a preset ('none', 'dev',
  49. 'combined', 'short', 'tiny' or 'logstalgia') or supply a custom format
  50. (e.g. ':method -> :url').
  51. -d, --directory <string> Root directory, defaults to the current directory
  52. -c, --compress Enables compression
  53. -r, --refresh-rate <number> Statistics view refresh rate in ms. Defaults to 500.
  54. Misc
  55. -h, --help Print these usage instructions
  56. --config Print the stored config
  57. ```
  58. From the folder you wish to serve, run:
  59. ```sh
  60. $ ws
  61. serving at http://localhost:8000
  62. ```
  63. If you wish to serve a different directory, run:
  64. ```sh
  65. $ ws -d ~/mysite/
  66. serving /Users/Lloyd/mysite at http://localhost:8000
  67. ```
  68. If you wish to override the default port (8000), use `--port` or `-p`:
  69. ```sh
  70. $ ws --port 9000
  71. serving at http://localhost:9000
  72. ```
  73. To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
  74. ```sh
  75. $ ws --compress
  76. ```
  77. ### Logging
  78. Passing a value to `--log-format` will write an access log to `stdout`.
  79. Either use a built-in [morgan](https://github.com/expressjs/morgan) logger preset:
  80. ```sh
  81. $ ws --log-format short
  82. ```
  83. Or a custom [morgan](https://github.com/expressjs/morgan) log format:
  84. ```sh
  85. $ ws -f ':method -> :url'
  86. ```
  87. Or silence:
  88. ```sh
  89. $ ws -f none
  90. ```
  91. ## Storing default options
  92. 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`:
  93. ```json
  94. {
  95. "name": "my-project",
  96. "version": "0.11.8",
  97. "local-web-server":{
  98. "port": 8100
  99. }
  100. }
  101. ```
  102. Or in a `.local-web-server.json` file stored in the directory you want to serve (typically the root folder of your site):
  103. ```json
  104. {
  105. "port": 8100,
  106. "log-format": "tiny"
  107. }
  108. ```
  109. Or store global defaults in a `.local-web-server.json` file in your home directory.
  110. ```json
  111. {
  112. "port": 3000,
  113. "refresh-rate": 1000
  114. }
  115. ```
  116. All stored defaults are overriden by options supplied at the command line.
  117. To view your stored defaults, run:
  118. ```sh
  119. $ ws --config
  120. ```
  121. ## mime-types
  122. 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:
  123. ```json
  124. {
  125. "mime": {
  126. "text/plain": [ "php", "pl" ]
  127. }
  128. }
  129. ```
  130. ## Use with Logstalgia
  131. local-web-server is compatible with [logstalgia](http://code.google.com/p/logstalgia/).
  132. ### Install Logstalgia
  133. On MacOSX, install with [homebrew](http://brew.sh):
  134. ```sh
  135. $ brew install logstalgia
  136. ```
  137. Alternatively, [download a release for your system from github](https://github.com/acaudwell/Logstalgia/releases/latest).
  138. Then pipe the `logstalgia` output format directly into logstalgia for real-time visualisation:
  139. ```sh
  140. $ ws -f logstalgia | logstalgia -
  141. ```
  142. ![local-web-server with logstalgia](http://75lb.github.io/local-web-server/logstagia.gif)
  143. ## Use with glTail
  144. To use with [glTail](http://www.fudgie.org), write your log to disk using the "default" format:
  145. ```sh
  146. $ ws -f default > web.log
  147. ```
  148. Then specify this file in your glTail config:
  149. ```yaml
  150. servers:
  151. dev:
  152. host: localhost
  153. source: local
  154. files: /Users/Lloyd/Documents/MySite/web.log
  155. parser: apache
  156. color: 0.2, 0.2, 1.0, 1.0
  157. ```
  158. &copy; 2015 Lloyd Brookes <75pound@gmail.com>