Skip to content
Lloyd Brookes edited this page Mar 13, 2022 · 19 revisions
$ ws --help

local-web-server

  A lean, modular web server for rapid full-stack development.

Synopsis

  $ ws <options>

Server Options

  Options set on the server.

  --port, -p number             The port number to listen on.
  --hostname string             The hostname or IP address to bind to. Defaults to 0.0.0.0 (any host).
  --max-connections number      The maximum number of concurrent connections supported by the server.
  --keep-alive-timeout number   The period (in milliseconds) of inactivity a connection will remain open
                                before being destroyed. Set to `0` to keep connections open indefinitely.

  HTTPS/TLS specific options.

  --https                    Enable HTTPS using a built-in TLS certificate registered to the hosts
                             127.0.0.1 and localhost.
  --http2                    Enable HTTP2 using a built-in TLS certificate registered to the hosts
                             127.0.0.1 and localhost.
  --key file                 Private key. Supply along with --cert to launch a https server.
  --cert file                Certificate chain. Supply along with --key to launch a https server.
  --pfx file                 Optional PFX or PKCS12 encoded private key and certificate chain. An
                             alternative to providing --key and --cert.
  --ciphers string           Optional cipher suite specification, replacing the default.
  --secure-protocol string   Optional SSL method to use, default is "SSLv23_method".

Extension Options

  --stack path ...   Construct a middleware stack using the modules provided.
  --view path        A path to a custom view module

Middleware stack

  ↓ BasicAuth        Password-protect a server using Basic Authentication.
  ↓ BodyParser       Parses the request body, making `ctx.request.body` available to downstream middleware.
  ↓ RequestMonitor   Feeds traffic information to the `--verbose` output.
  ↓ Log              Outputs an access log or stats view to the console.
  ↓ Cors             Support for setting Cross-Origin Resource Sharing (CORS) headers.
  ↓ Json             Pretty-prints JSON responses. Also converts node object streams to binary.
  ↓ Compress         Compress responses using gzip.
  ↓ Rewrite          URL Rewriting. Use to re-route requests to local or remote destinations.
  ↓ Blacklist        Forbid access to sensitive or private resources.
  ↓ ConditionalGet   Support for HTTP Conditional requests.
  ↓ Mime             Customise the mime-type returned with any static resource.
  ↓ Range            Support for HTTP Range Requests.
  ↓ SPA              Support for Single Page Applications.
  ↓ Static           Serves static files.
  ↓ Index            Serves directory listings.

Middleware options

  --auth.user string              Basic authentication username
  --auth.pass string              Basic authentication password
  --log.format, -f string         Possible values: 'stats', 'logstalgia' or anything defined by
                                  https://github.com/expressjs/morgan, typically 'dev', 'combined', 'short',
                                  'tiny' or a custom format (e.g. ':method -> :url')
  --cors.origin string            `Access-Control-Allow-Origin` value. Default is the request Origin header.
  --cors.allow-methods string     `Access-Control-Allow-Methods` value. Default is
                                  "GET,HEAD,PUT,POST,DELETE,PATCH"
  --cors.credentials              Adds `Access-Control-Allow-Credentials` header.
  --cors.opener-policy string     A value for the `Cross-Origin-Opener-Policy` header (specify `unsafe-none`,
                                  same-origin-allow-popups` or `same-origin`).
  --cors.embedder-policy string   A value for the `Cross-Origin-Embedder-Policy` header (specify `unsafe-none`
                                  or `require-corp`).
  --compress, -z                  Serve gzip-compressed resources, where applicable.
  --compress.threshold number     Minimum response size in bytes to apply compression. Defaults to 1024.
  --rewrite, -r expression ...    A list of URL rewrite rules. For each rule, separate the 'from' and 'to'
                                  routes with '->'. Whitespace surrounding the routes is ignored. E.g. '/from
                                  -> /to'.
  --rewrite.keep-secure-attr      When local-web-server is running in plain, insecure HTTP mode (not HTTPS or
                                  HTTP2), stripping the `secure` attribute from remote, rewrite-target cookies
                                  is the default behaviour. Set this flag to leave remote `secure` cookies
                                  untouched - this may prevent cookies functioning correctly when your server
                                  is plain HTTP.
  --blacklist path ...            A list of routes to forbid, e.g. `--blacklist "/admin/(.*)" "(.*).php"`
  --no-conditional-get, -n        Disable Conditional-GET caching. Force-loads resources from disk each
                                  request.
  --spa, -s file                  Path to a Single Page App, e.g. app.html.
  --spa.asset-test RegExp         A regular expression to identify an asset file. Defaults to ".", meaning the
                                  server will only read from disk if the requested path contains a ".". This
                                  option is more efficient than `spa.asset-test-fs`.
  --spa.asset-test-fs             Use the filesystem to identify an asset file. If the file exists on disk,
                                  serve it else return the SPA. If specified, `spa.asset-test` will be ignored.
                                  This option is less efficient but more reliable than `spa.asset-test`.
  --directory, -d path            Root directory, defaults to the current directory.
  --static.maxage number          Cache max-age (in seconds) applied to all resources served.
  --static.defer                  If true, serves after `await next`, allowing any downstream middleware to
                                  respond first.
  --static.index path             Default file name, defaults to `index.html`.
  --static.extensions ext         One or more default filename extensions. For example, if you set
                                  `--static.extensions html` and request `/page` then the server will look for
                                  both `page` and `page.html` on disk, serving the latter.
  --index.root path               Index root directory, defaults to the same value as --directory or the
                                  current directory.
  --index.hidden                  Show hidden files.
  --index.view name               Display mode, either `tiles` or `details`. Defaults to tiles.

View options

  --qr network interface       Enables you to quickly launch your web app in a mobile browser by scanning a
                               QR code. The QR code for the URL of the specified network interface (e.g.
                               `--qr en0`) is printed. If no interface is specified (`--qr`) it defaults to
                               printing a QR for the first found private address (e.g. `192.168.0.1`). See
                               `--list-network-interfaces` for a list of your current network interface
                               names.
  --verbose, -v                Outputs a highly verbose JSON stream containing debug information. Intended
                               as a datasource for custom views.
  --verbose.include string[]   One or more regular expressions describing which event keys to include in
                               verbose output. Implies --verbose.
  --verbose.exclude string[]   One or more regular expressions describing which event keys to exclude from
                               verbose output. Implies --verbose.

Misc Options

  --help, -h                   Print these usage instructions.
  --version                    Print the version number.
  --config-file, -c file       Filename to retrieve stored config from. Defaults to "lws.config.js".
  --config                     Print the active config.
  --open, -o                   Automatically open the default system browser.
  --list-network-interfaces    Print a list of available network interfaces. Used in conjunction with
                               `--qr`.
  --default-stack              Print the default middleware stack. Any of these built-in middlewares are
                               available to use in a custom stack.

  Project home: https://github.com/lwsjs/local-web-server
Clone this wiki locally