Skip to content
SZ edited this page May 24, 2018 · 19 revisions

local-web-server

The modular web server for productive full-stack development.

Synopsis

$ ws <options>         
$ ws command <options> 

Server Options

  • Options set on the server.
  --port, -p number             Web server port.                                                              
  --hostname string             The hostname (or IP address) to listen on. 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. 
  --server path      Custom server factory, e.g. lws-http2                    
  --websocket path   A path to a websocket module                             
  --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.                             
  ↓ Cors             Support for HTTP Range Requests.                                                       
  ↓ MockResponse     Mock a response for any given request.                                                 
  ↓ 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                  `Access-Control-Allow-Origin` value. Default is the request Origin header.    
  --cors.allow-methods           `Access-Control-Allow-Methods` value. Default is                              
                                 "GET,HEAD,PUT,POST,DELETE,PATCH"                                              
  --cors.credentials             Adds `Access-Control-Allow-Credentials` header.                               
  --compress, -z                 Serve gzip-compressed resources, where applicable.                            
  --compress.threshold number    Minimum response size in bytes to apply compression. Defaults to 1024 bytes.  
  --rewrite, -r 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'.                                                                         
  --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.                                                                      
  --mocks file ...               One or more modules exporting Mock Responses.                                 
  --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 ".".              
  --directory, -d path           Root directory, defaults to the current directory.                            
  --static.maxage number         Cache max-age (in seconds) applied to all static 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`.                                  
  --index.root path              Index root directory, defaults to --directory or the current directory.       
  --index.hidden                 Show hidden files.                                                            
  --index.view name              Display mode, either `tiles` or `details`. Defaults to tiles.                 
  • View options
  --verbose, -v        Outputs a highly verbose JSON stream containing debug information. Intended   
                       as a datasource for custom views.                                             
  --verbose.include    One or more regular expressions describing which event keys to include in     
                       verbose output. Implies --verbose.                                            
  --verbose.exclude    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   Config filename to use, defaults to "lws.config.js". 
  --config                 Print the active config.                             
  • Commands
  middleware-list   Print available middleware 

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