5

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!

1
  • Could you please give snapshot of angular.json Commented Jun 14, 2022 at 15:22

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

I think important part here (for me) was the adding -nodes so the key wasn't encrypted
3

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/...

1 Comment

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
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.