Skip to content

How to launch a secure local web server (HTTPS)

Lloyd Brookes edited this page Dec 7, 2017 · 6 revisions

Some modern techs (HTTP2, ServiceWorker, MediaDevices.getUserMedia() etc.) must be served from a secure origin (HTTPS). To launch an HTTPS server you must supply one of the following:

  1. the --https flag
  2. --key and --cert files
  3. a --pfx file

The quickest method is to use the --https flag, this will use the private key and certificate chain built into local-web-server. This example will serve your current project as a secure, static web site.

  1. Install local-web-server to get the ws command
$ npm install -g local-web-server
  1. Navigate into to your project
$ cd example-project
  1. Launch the secure webserver.
$ ws --https
Serving at https://mbp.local:8000, https://127.0.0.1:8000, https://192.168.0.100:8000
  1. Navigating to one of the listed URLs will render a directory listing or your index.html, if that file exists.

Next, read how to get the "green padlock" using the built-in certificate.

Clone this wiki locally