通过HTTPS获取angular-cli进行投放 [英] Get angular-cli to ng serve over HTTPS

查看:88
本文介绍了通过HTTPS获取angular-cli进行投放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下内容似乎无济于事.

The following doesn't seem to do anything.

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


通过在默认的ssl目录中提供证书和密钥来创建证书和密钥仍然没有任何作用.


Creating the Certificate and key by providing them in the default ssl directory still does nothing.

ng server似乎完全忽略了--ssl参数,并一直说NG Live Development Server is running on http://localhost:4200.

It looks like ng server is completely ignoring the --ssl parameter and keeps saying NG Live Development Server is running on http://localhost:4200.

推荐答案

Angular CLI 6 +

我已经更新了自己的项目,所以我现在也可以更新此答案.

Angular CLI 6+

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

您现在将如下所示将密钥和证书的路径放入您的angular.json文件中:

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": {
       "<PROJECT-NAME>": {
           "architect": {
               "serve: {
                   "options": {
                       "sslKey": "<relative path from angular.json>/server.key",
                       "sslCert": "<relative path from angular.json>/server.crt",
                       ...
                   }, ...
               }, ...
           }, ...
       }, ...
   }, ...
}

然后您可以运行:

ng serve --ssl

如果默认情况下要启用SSL,则应在 sslKey sslCert 的正下方添加"ssl":true,选项.

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

您可以在 Angular CLI文档.

Angular-CLI现在可以使用SSL选项.如前所述,您可以通过以下命令手动选择要使用的密钥和证书:

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>

如果您想为密钥和证书设置默认路径,则可以进入.angular-cli.json文件,相应地调整默认值"部分:

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",
            ...
        }, ...
    }, ...
}

然后您可以运行:

ng serve --ssl

如果默认情况下要启用SSL,则应在 sslKey sslCert 的正下方添加"ssl":true,选项.

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

这篇关于通过HTTPS获取angular-cli进行投放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆