Get angular-cli to ng serve over HTTPS

后端 未结 9 1504
一整个雨季
一整个雨季 2020-11-28 02:59

The following doesn\'t seem to do anything.

ng serve --ssl true --ssl-key  --ssl-cert 

Creating the

9条回答
  •  情话喂你
    2020-11-28 03:43

    Angular CLI 6+

    I've updated my own projects so I figured I can now update this answer too.

    You'll now put the path to your key and certificate in your angular.json file as follows:

    {
       "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
       "projects": {
           "": {
               "architect": {
                   "serve: {
                       "options": {
                           "sslKey": "/server.key",
                           "sslCert": "/server.crt",
                           ...
                       }, ...
                   }, ...
               }, ...
           }, ...
       }, ...
    }
    

    And then you can run:

    ng serve --ssl
    

    If you want SSL on by default then you should add a "ssl": true, option immediately below the sslKey and sslCert.

    You can find the angular.json schema at the Angular CLI documentation.

    Old answer for Angular CLI 1.0.0+.

    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  --ssl-cert 
    

    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": "/server.key",
                "sslCert": "/server.crt",
                ...
            }, ...
        }, ...
    }
    

    And then you can run:

    ng serve --ssl
    

    If you want SSL on by default then you should add a "ssl": true, option immediately below the sslKey and sslCert.

提交回复
热议问题