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.

159 lines
4.1 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
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
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
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
  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, 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. Install [Node.js](http://nodejs.org), then run
  12. ```sh
  13. $ npm install -g local-web-server
  14. ```
  15. *Linux/Mac users may need to run the above with `sudo`*
  16. Usage
  17. -----
  18. ```
  19. Usage
  20. $ ws <server options>
  21. $ ws --config
  22. $ ws --help
  23. Server
  24. -p, --port <number> Web server port
  25. -f, --log-format <string> If a format is supplied an access log is written to stdout. If not,
  26. a statistics view is displayed. Use a preset ('none', 'dev',
  27. 'default', 'short', 'tiny' or 'logstalgia') or supply a custom format
  28. (e.g. ':method -> :url').
  29. -d, --directory <string> Root directory, defaults to the current directory
  30. -c, --compress Enables compression
  31. -r, --refresh-rate <number> Statistics view refresh rate in ms. Defaults to 500.
  32. Misc
  33. -h, --help Print these usage instructions
  34. --config Print the stored config
  35. ```
  36. From the folder you wish to serve, run:
  37. ```sh
  38. $ ws
  39. serving at http://localhost:8000
  40. ```
  41. If you wish to serve a different directory, run:
  42. ```sh
  43. $ ws -d ~/mysite/
  44. serving /Users/Lloyd/mysite at http://localhost:8000
  45. ```
  46. If you wish to override the default port (8000), use `--port` or `-p`:
  47. ```sh
  48. $ ws --port 9000
  49. serving at http://localhost:9000
  50. ```
  51. To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
  52. ```sh
  53. $ ws --compress
  54. ```
  55. ###Logging
  56. Passing a value to `--log-format` will write an access log to `stdout`.
  57. Either use a built-in [morgan](https://github.com/expressjs/morgan) logger preset:
  58. ```sh
  59. $ ws --log-format short
  60. ```
  61. Or a custom [morgan](https://github.com/expressjs/morgan) log format:
  62. ```sh
  63. $ ws -f ':method -> :url'
  64. ```
  65. Or silence:
  66. ```sh
  67. $ ws -f none
  68. ```
  69. Storing default options
  70. -----------------------
  71. 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`:
  72. ```json
  73. {
  74. "name": "my-project",
  75. "version": "0.11.8",
  76. "local-web-server":{
  77. "port": 8100
  78. }
  79. }
  80. ```
  81. Or in a `.local-web-server.json` file stored in the directory you want to serve (typically the root folder of your site):
  82. ```json
  83. {
  84. "port": 8100,
  85. "log-format": "tiny"
  86. }
  87. ```
  88. Or store global defaults in a `.local-web-server.json` file in your home directory.
  89. ```json
  90. {
  91. "port": 3000,
  92. "refresh-rate": 1000
  93. }
  94. ```
  95. All stored defaults are overriden by options supplied at the command line.
  96. To view your stored defaults, run:
  97. ```sh
  98. $ ws --config
  99. ```
  100. Use with Logstalgia
  101. -------------------
  102. local-web-server is compatible with [logstalgia](http://code.google.com/p/logstalgia/).
  103. ###Install Logstalgia
  104. On MacOSX, install with [homebrew](http://brew.sh):
  105. ```sh
  106. $ brew install logstalgia
  107. ```
  108. Alternatively, [download a release for your system from github](https://github.com/acaudwell/Logstalgia/releases/latest).
  109. Then pipe the `logstalgia` output format directly into logstalgia for real-time visualisation:
  110. ```sh
  111. $ ws -f logstalgia | logstalgia -
  112. ```
  113. ![local-web-server with logstalgia](http://75lb.github.io/local-web-server/logstagia.gif)
  114. Use with glTail
  115. ---------------
  116. To use with [glTail](http://www.fudgie.org), write your log to disk using the "default" format:
  117. ```sh
  118. $ ws -f default > web.log
  119. ```
  120. Then specify this file in your glTail config:
  121. ```yaml
  122. servers:
  123. dev:
  124. host: localhost
  125. source: local
  126. files: /Users/Lloyd/Documents/MySite/web.log
  127. parser: apache
  128. color: 0.2, 0.2, 1.0, 1.0
  129. ```