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
4.8 KiB

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