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.

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