We support #BlackLivesMatters !
If you support us then follow us by clicking here and following us!

How to run Angular CLI using localhost over https?

Get support on Angular & Typescript related technology.
Post Reply
admin
Site Admin
Posts: 44

How to run Angular CLI using localhost over https?

Post by admin » Thu Aug 22, 2019 2:58 pm

Image

The easiest method I can find is to install browser-sync as a dev dependency.

Code: Select all

npm install browser-sync --save-dev
This will install a self-signed certificate and key for localhost, which you can now point to when adding the --ssl
switches.

Open your package.json in root folder of your angular project and change the start script to the following:

Code: Select all

ng serve --ssl true --ssl-key /node_modules/browser-sync/lib/server/certs/server.key --ssl-cert /node_modules/browser-sync/lib/server/certs/server.crt
Now, when you call ng start NPM will run ng serve with the additional SSL switches, and serve your site under HTTPS (e.g. https://localhost:4200).

Post Reply