4

When I try to use ng serve using ssl with custom host name I will get the An unhandled exception occurred: Dev-server address info is not defined. error. I was wondering if anyone has a solution for this problem.

ng serve --host myapp.local --port 4200 --ssl --ssl-key 'certs/myapp.local.key' --ssl-cert 'certs/myapp.local.crt'

myapp.local is set to 127.0.0.1 at the host file. and I also added

"options": { "disableHostCheck": true, "allowedHosts": ["myapp.local"], "sslCert": "certs/myapp.local.crt", "sslKey": "certs/myapp.local.key", "browserTarget": "latest-angular:build", "host": "myapp.local", "port": 4200, "ssl": true }

Any helps would be appreciated!

Ryan Tavan
  • 121
  • 2
  • 6

3 Answers3

4

In my case, the problem was with the not correctly generated self-signed certificate. This command has correctly generated the certificate:

openssl req -newkey rsa:2048 -keyout localhost.key -x509 -days 3650 -out localhost.crt -nodes -sha256

1

I had this exact error, doing the same thing.

For me, it was a problem to do with the location of the certificate - I had some incorrect casing referring to it :facepalm: Fixing the casing solved the issue.

"sslCert": "../Development/ssl/... should have been "sslCert": "../development/ssl/...

  • Same for me, the path to my .`crt` and `.key` were wrong, hence producing this error. One should check that it is relative to the `angular.json` – missing_semicolon Jun 17 '22 at 14:05
0

This exception usually occurs when due to the below scenarios,

Issue 1: Invalid Personal Certificate This can be fixed by provisioning a proper certificate, to create a self-signed local certificate, use openssl with the below command

openssl req -newkey rsa:2048 -keyout [keyfilename.key] -x509 -days 3650 -out [certificatefilename.crt] -nodes -sha256

Issue 2: Certificate key is encrypted with a passphrase, If your key is passphrase protected, use openssl with below command

openssl rsa -in [keyfilename-encrypted.key] -out [keyfilename-decrypted.key]

Issue 3: Improper path to the certificate or key file, The ng serve command picks the relative path from the application base folder and not the src folder. You can find your application base folder by looking for the file 'angular.json'.

Example : E:\Coding\Urban Online\angular.shoppers.client\client-app\src>ng serve --ssl true --ssl-cert ./urbanonline.selfsigned.crt --ssl-key ./urbanonline.selfsigned.plain.key Here, I have placed the cert and key within the client-app folder.

Hope this helps for people like me in future.