How to get angular-cli to ng serve over HTTPS

Multi tool use
Multi tool use


How to get angular-cli to ng serve over HTTPS



The following doesn't seem to do anything.


ng serve --ssl true --ssl-key <key-path> --ssl-cert <cert-path>



Creating the Certificate and key by providing them in the default ssl directory still does nothing. It looks like ng server is completely ignoring the ssl parameter and keeps saying NG Live Development Server is running on http://localhost:4200.


NG Live Development Server is running on http://localhost:4200.





try ng serve --ssl 1 --ssl-key "ssl/local.brianflove.com.key" --ssl-cert "ssl/local.brianflove.com.crt"
– Andreas
Sep 26 '17 at 10:15




4 Answers
4



As stated in a previous comment, Angular-CLI now works with the SSL options. Like you've noted, you can manually select which key and cert you'd like to use with the command:


ng serve --ssl --ssl-key <key-path> --ssl-cert <cert-path>



If you'd like to set a default path for your key and cert then you can go into your .angular-cli.json file adjust the Defaults section accordingly:


{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
...
"defaults": {
...
"serve": {
"sslKey": "<relative path from .angular-cli.json>/server.key",
"sslCert": "<relative path from .angular-cli.json>/server.crt"
},
...
},
...
}



And then you can run:


ng serve --ssl





"ssl" : "true" will start ssl by default
– Dominik K
May 23 at 16:31





@Dominik, where to write "ssl" : "true" . Can you tell me either in ng serve command or in angular-cli.json. Thank you
– Ahmad mnzr
7 hours ago



To complement this solution, if you ever wonder how to generate key and certificate for localhost, here is a great step by step article about it:



https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec



You are correct. The current implementation does not take the ssl configuration options under account. I have created a pull request that fixes this issue. However it has not been merged yet in the master at the time of this writing.





This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Jason Yost
Oct 9 '16 at 18:29





The latest version of angular-cli fixes the issue. So to fix the issue all you have to do is upgrade to latest angular-cli
– Stefan Baramov
Oct 25 '16 at 15:55



JFYI, in Angular6 you have to put the conf in the options (in angular.json) :


"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "app:build",
"ssl": true,
"sslKey": "path to .key",
"sslCert": "path to .crt"
},
...
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

G4,CoEiN1lMwE1ttl8R5j6saB3MRwTx 3Rr4y9ukvlPg FK0hXmnZe4 3o rdEr,CziY0sS NhXcu9KOcu
2foJY3iF,6f9teFlrvhCWofUgbX4Q G0Mrok nRvCOlirGaYDXhEthueGF10O0pad7f,wiVw,I9uoJWkwht,b1v3O 9Z D Wax4f HeENG

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications