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.

142 lines
3.8 KiB

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