首页 > 解决方案 > 使用 rejoice 在 NodeJS 中启用 https

问题描述

我在 HapiJS 上构建了 nodejs 微服务。为了启动服务器,我们使用 rejoice,它使用 .json 文件进行配置。 "server": { }, "connections": [ { "port": 5000, "host": "0.0.0.0" } ]

当我们使用 rejoice 命令启动服务器时,选择了上面的端口配置。现在我们尝试使用 https 运行 nodejs 服务,但我不知道该怎么做。我看到 hapi 文档说传递 tls 对象作为连接参数的一部分将被发送,因为它是 nodejs。请参阅Hapi 服务器选项。现在我尝试在连接数组中传递 tls 对象

"connections": [
    {
        "port": 5000,
        "host": "0.0.0.0"
        "tls" :{
            "cert":"./server_certificate.pem",
            "key": "./server_key.pem"               
         }
    }
]

然后在下面。

Problems while parsing the config_prod.json file. Make sure the file exists and is well formatted. 
Error: Unexpected string in JSON at position 116
./change_request/node_modules/glue/node_modules/joi/lib/index.js:144
throw error;
ValidationError: Invalid manifest "value" must be an object

标签: node.jshapijs

解决方案


它不是有效的 json,因为您在主机后缺少逗号。它应该是

"connections": [
    {
        "port": 5000,
        "host": "0.0.0.0",
        "tls" :{
            "cert":"./server_certificate.pem",
            "key": "./server_key.pem"               
         }
    }
]

推荐阅读