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.
 
 
 
Lloyd Brookes 7910a424c2 refactor, linting 8 years ago
bin refactor, linting 8 years ago
doc log.format, error reporting 8 years ago
example update stack examples and deps 8 years ago
jsdoc2md docs 8 years ago
lib refactor, linting 8 years ago
ssl add --https option. Fixes #31 8 years ago
test log.format, error reporting 8 years ago
.coveralls.yml docs.. tidy.. examples.. --rewrite 9 years ago
.gitignore mock responses.. example 9 years ago
.travis.yml upgrade deps and travis 8 years ago
LICENSE update docs 8 years ago
README.md log.format, error reporting 8 years ago
package.json refactor, linting 8 years ago

README.md

view on npm npm module downloads Build Status Dependency Status js-standard-style Join the chat at https://gitter.im/75lb/local-web-server

Requires node v4.0.0 or higher. Install the previous release for older node support.

local-web-server

An application shell for building a simple, command-line web server for productive web development. It contains no middleware of its own but will load default-stack unless you specify otherwise.

It is trivial is bundle and deploy with your project. Also deploys to heroku well for demo projects.

It comes with some middleware built-in, which you need not use but will get you up and running for the following use cases:

  • Static or Single Page Application front-end development where you have
    • No backend, an existing remote API or need to mock-up an API.

Application Shell

  • HTTP or HTTPS server
    • HTTPS is strictly required by some modern techs (ServiceWorker, Media Capture and Streams etc.)
  • Add your middleware
    • Use any combination of built-in and custom middleware
    • specify options (for command line or config)
    • Accepts Koa v1 or 2 middleware
  • Bundle with your front-end project
  • Configuration is via json file or command-line (latter taking precedence)
  • Outputs a dynamic statistics view to the terminal

Built-in Middleware (all optional)

  • Rewrite routes to local or remote resources
  • Efficient, predictable, entity-tag-powered conditional request handling (no need to 'Disable Cache' in DevTools, slowing page-load down)
  • Configurable log output, compatible with Goaccess, Logstalgia and glTail
  • Proxy server
    • Map local routes to remote servers. Removes CORS pain when consuming remote services.
  • Back-end service mocking
    • Prototype a web service, microservice, REST API etc.
    • Mocks are defined with config (static), or code (dynamic).
  • CORS-friendly, all origins allowed by default.

Synopsis

local-web-server is a command-line tool. To serve the current directory, run ws.

$ ws --help

local-web-server

  A simple web-server for productive front-end development.

Synopsis

  $ ws [--verbose] [] []
  $ ws --config
  $ ws --help

Server

  -p, --port number   Web server port.
  --key file          SSL key. Supply along with --cert to launch a https server.
  --cert file         SSL cert. Supply along with --key to launch a https server.
  --https             Enable HTTPS using a built-in key and cert, registered to the domain
                      127.0.0.1.

Middleware

  -r, --rewrite expression ...   A list of URL rewrite rules. For each rule, separate the 'from' and 'to'
                                 routes with '->'. Whitespace surrounded the routes is ignored. E.g. '/from ->
                                 /to'.
  -b, --forbid path ...          A list of forbidden routes.
  -n, --no-cache                 Disable etag-based caching -forces loading from disk each request.
  -c, --compress                 Serve gzip-compressed resources, where applicable.
  -f, --log.format string        If a format is supplied an access log is written to stdout. If not, a dynamic
                                 statistics view is displayed. Use a preset ('none', 'dev','combined',
                                 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method ->
                                 :url').
  -s, --spa file                 Path to a Single Page App, e.g. app.html.
  -d, --directory path           Root directory, defaults to the current directory.

Misc

  -h, --help    Print these usage instructions.
  --config      Print the stored config.

  Project home: https://github.com/75lb/local-web-server

Examples

For the examples below, we assume we're in a project directory looking like this:

.
├── css
│   └── style.css
├── index.html
└── package.json

All paths/routes are specified using express syntax. To run the example projects linked below, clone the project, move into the example directory specified, run ws.

Static site

Fire up your static site on the default port:

$ ws
serving at http://localhost:8000

Example.

Install

Ensure node.js is installed first. Linux/Mac users may need to run the following commands with sudo.

$ npm install -g local-web-server

© 2013-16 Lloyd Brookes 75pound@gmail.com. Documented by jsdoc-to-markdown.