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.

155 lines
3.7 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 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](http://img.shields.io/npm/dt/local-web-server.svg)](https://www.npmjs.org/package/local-web-server)
  3. [![Build Status](https://travis-ci.org/75lb/local-web-server.svg?branch=master)](https://travis-ci.org/75lb/local-web-server)
  4. [![Dependency Status](https://david-dm.org/75lb/local-web-server.svg)](https://david-dm.org/75lb/local-web-server)
  5. [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
  6. # local-web-server
  7. A simple web-server for productive front-end development.
  8. **Requires node v4.0.0 or higher**.
  9. ## Synopsis
  10. Some typical use cases..
  11. ### Static site
  12. Fire up your site on the default port:
  13. ```sh
  14. $ tree
  15. .
  16. ├── css
  17. │   └── style.css
  18. └── index.html
  19. $ ws
  20. serving at http://localhost:8000
  21. ```
  22. ### Single Page Application
  23. Mark `index.html` as an SPA with client-side routing.
  24. ```sh
  25. $ ws --spa index.html
  26. ```
  27. With this option, routes with existing files (e.g. `/css/style.css`) will be served normally as static assets. Routes without an existing file (e.g. `/user/1`, `/login` etc.) are passed directly to your SPA. Without this option they would 404.
  28. Blacklist certain paths, for example config files:
  29. ```sh
  30. $ ws --forbid .json .yml
  31. serving at http://localhost:8000
  32. ```
  33. Reduce bandwidth with gzip compression:
  34. ```sh
  35. $ ws --compress
  36. ```
  37. When urls don't map to your directory structure, rewrite:
  38. ```sh
  39. $ ws --rewrite /css=>/build/css
  40. ```
  41. Rewrite to remote servers:
  42. ```sh
  43. $ ws --rewrite /api=>http://api.example.com/api /npm=>http://registry.npmjs.com
  44. ```
  45. ## Install
  46. Ensure [node.js](http://nodejs.org) is installed first. Linux/Mac users may need to run the following commands with `sudo`.
  47. ```sh
  48. $ npm install -g local-web-server
  49. ```
  50. ## Distribute with your project
  51. ```sh
  52. $ npm install local-web-server --save-dev
  53. ```
  54. Then add an `start` script to your `package.json` (the standard npm approach):
  55. ```json
  56. {
  57. "name": "my-web-app",
  58. "version": "1.0.0",
  59. "scripts": {
  60. "start": "ws"
  61. }
  62. }
  63. ```
  64. This simplifies a rather specific-looking instruction set like:
  65. ```sh
  66. $ npm install
  67. $ npm install -g local-web-server
  68. $ ws
  69. ```
  70. to the following, server implementation and launch details abstracted away:
  71. ```sh
  72. $ npm install
  73. $ npm start
  74. ```
  75. ## Storing default options
  76. 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`:
  77. ```json
  78. {
  79. "name": "my-project",
  80. "version": "0.11.8",
  81. "local-web-server":{
  82. "port": 8100
  83. }
  84. }
  85. ```
  86. Or in a `.local-web-server.json` file stored in the directory you want to serve (typically the root folder of your site):
  87. ```json
  88. {
  89. "port": 8100,
  90. "log-format": "tiny"
  91. }
  92. ```
  93. Or store global defaults in a `.local-web-server.json` file in your home directory.
  94. ```json
  95. {
  96. "port": 3000,
  97. "refresh-rate": 1000
  98. }
  99. ```
  100. All stored defaults are overriden by options supplied at the command line.
  101. To view your stored defaults, run:
  102. ```sh
  103. $ ws --config
  104. ```
  105. ## mime-types
  106. You can set additional mime-type/extension mappings, or override the defaults by setting a `mime` value in your local config. This value is passed directly to [mime.define()](https://github.com/broofa/node-mime#mimedefine). Example:
  107. ```json
  108. {
  109. "mime": {
  110. "text/plain": [ "php", "pl" ]
  111. }
  112. }
  113. ```
  114. ## Use with Google DevTools Workspaces
  115. ## Log Visualisation
  116. Instructions for how to visualise log output using goaccess, logstalgia or gltail [here](https://github.com/75lb/local-web-server/wiki/Log-visualisation).
  117. ## API Reference
  118. {{>main}}
  119. * * *
  120. &copy; 2015 Lloyd Brookes <75pound@gmail.com>