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.

141 lines
3.7 KiB

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