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.

124 lines
3.1 KiB

11 years ago
11 years ago
11 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
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
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. [![NPM version](https://badge.fury.io/js/local-web-server.png)](http://badge.fury.io/js/local-web-server)
  2. [![Dependency Status](https://david-dm.org/75lb/local-web-server.png)](https://david-dm.org/75lb/local-web-server)
  3. ![Analytics](https://ga-beacon.appspot.com/UA-27725889-12/local-web-server/README.md?pixel)
  4. local-web-server
  5. ================
  6. Fires up a simple, static web server on a given port. A pure Javascript (and more reliable) alternative to `$ python -mSimpleHTTPServer 8000`.
  7. Use for local web development or file sharing (directory browsing enabled). Plays well with Google Chrome Workspaces.
  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. ws [--directory|-d <directory>] [--port|-p <port>] [--log-format|-f dev|default|short|tiny] [--compress|-c]
  19. ```
  20. From the folder you wish to serve, run:
  21. ```sh
  22. $ ws
  23. serving at http://localhost:8000
  24. ```
  25. If you wish to serve a different directory, run:
  26. ```sh
  27. $ ws -d ~/mysite/
  28. serving /Users/Lloyd/mysite at http://localhost:8000
  29. ```
  30. If you wish to override the default port (8000), use `--port` or `-p`:
  31. ```sh
  32. $ ws --port 9000
  33. serving at http://localhost:9000
  34. ```
  35. Use a built-in or custom [Connect logger format](http://www.senchalabs.org/connect/logger.html) with `--log-format`:
  36. ```sh
  37. $ ws --log-format short
  38. ```
  39. To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
  40. ```sh
  41. $ ws --compress
  42. ```
  43. Storing default options
  44. -----------------------
  45. 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`:
  46. ```json
  47. {
  48. "name": "my-project",
  49. "version": "0.11.8",
  50. "local-web-server":{
  51. "port": 8100
  52. }
  53. }
  54. ```
  55. Or in a `.local-web-server.json` file stored in the directory you want to serve (typically the root folder of your site):
  56. ```json
  57. {
  58. "port": 8100,
  59. "log-format": "tiny"
  60. }
  61. ```
  62. Or store global defaults in a `.local-web-server.json` file in your home directory.
  63. ```json
  64. {
  65. "port": 3000
  66. }
  67. ```
  68. All stored defaults are overriden by options supplied at the command line.
  69. Use with Logstalgia
  70. -------------------
  71. The "default" log-format is compatible with [logstalgia](http://code.google.com/p/logstalgia/).
  72. If you wrote your log output to disk, like so:
  73. ```sh
  74. $ ws --log-format default > web.log
  75. ```
  76. Then you could visualise in logstalgia with:
  77. ```sh
  78. $ logstalgia web.log
  79. ```
  80. Alternatively, pipe directly from ws into logstalgia for real-time visualisation:
  81. ```sh
  82. $ ws --log-format default | logstalgia -
  83. ```
  84. Use with glTail
  85. ---------------
  86. To use with [glTail](http://www.fudgie.org), write your log to disk using the "default" format:
  87. ```sh
  88. $ ws -f default > web.log
  89. ```
  90. Then specify this file in your glTail config:
  91. ```yaml
  92. servers:
  93. dev:
  94. host: localhost
  95. source: local
  96. files: /Users/Lloyd/Documents/MySite/web.log
  97. parser: apache
  98. color: 0.2, 0.2, 1.0, 1.0
  99. ```
  100. [![NPM](https://nodei.co/npm-dl/local-web-server.png?months=3)](https://nodei.co/npm/local-web-server/)