2

My angular application doesnt use my created key or certificate. i created a directory "ssl" and put both files in there.

But the first time I "ng serve", angular creates its own keys (it was written in the terminal while it was compiling).

How can I tell angular to use my files?

Per Angular Docs it should be done in the angular.json, but like I said, the first "ng serve" creates its own key and do not use mine.

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

The Application runs on https already, just not with certificates I put in the angular.json.

Klaxx
  • 380
  • 1
  • 6
  • 22
  • Are you using ng serve for the deployed version of your site? In my case, I use ng build --prod to generate the deployable files and then host using IIS. I can then use an ssl binding within IIS. – Eddy Howard Jan 09 '19 at 20:30
  • Hey Eddy, thanks for replying. I am still developing on localhost, so i dont need to build yet and I dont know what IIS is. – Klaxx Jan 09 '19 at 21:09
  • 2
    Have a look at this [StackOverflow answer](https://stackoverflow.com/questions/39210467/get-angular-cli-to-ng-serve-over-https). That OP seems to want to know the same thing as you. If that doesn't help you can take a look at [this article](https://medium.com/@richardr39/using-angular-cli-to-serve-over-https-locally-70dab07417c8) or [this article](https://medium.com/@rubenvermeulen/running-angular-cli-over-https-with-a-trusted-certificate-4a0d5f92747a) both of which explain how to do it as well. Hope that helps. – Narm Jan 09 '19 at 22:51
  • Possible duplicate of [Get angular-cli to ng serve over HTTPS](https://stackoverflow.com/questions/39210467/get-angular-cli-to-ng-serve-over-https) – Narm Jan 09 '19 at 22:52
  • Hey Narm, thanks for the reply! My Application runs as https, just not with the right certificates. So it is not a duplicate. I will look into the other links you provided, because the stackoverflow answer you mentioned, I already tried that. – Klaxx Jan 10 '19 at 22:12

2 Answers2

2

You'd need to add the --ssl flag to your ng serve cmd if you are going through the angular json like so:

ng serve --ssl --host "0.0.0.0"

Dale K
  • 25,246
  • 15
  • 42
  • 71
tjee
  • 21
  • 5
  • Thanks for answering, but this is already mentioned in my question - in my angular json in the serve section. My question even says the app runs on https, just with the wrong certificates. Your comment doesnt answer my question. Have a great day – Klaxx Jul 17 '19 at 08:47
0

You can try to add it in your package.json file Under the scripts property, add it under start.

"scripts": {
  "ng": "ng",
  "start": "ng serve --open --ssl true --ssl-cert <path of your ssl cert in source file> --ssl-key <path of your ssl key in source file>,

 ........

And everytime you are going to start your app, you can run the script by

npm run start
Carl Sare
  • 191
  • 1
  • 14
  • 1
    Hi Carl, thanks for helping me out. Unfortunately this is the same as putting the certificates in angular.json. The app runs as https but with the wrong certificate again. It seems those --ssl cert and key commands get ignored. – Klaxx Jan 10 '19 at 22:30
  • Yes, I have the same problem. I put them into angular.json but when I check the certificate in browser its the generated from angular. – Blindworks Jan 06 '22 at 15:12