node.js - 使用 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
解决方案
它不是有效的 json,因为您在主机后缺少逗号。它应该是
"connections": [
{
"port": 5000,
"host": "0.0.0.0",
"tls" :{
"cert":"./server_certificate.pem",
"key": "./server_key.pem"
}
}
]
推荐阅读
- c - 避免 POSIX 线程中的内存泄漏
- java - 如何通过 config.properties 从 pom.xml 获取参数值
- javascript - problem with conditions in javascript while working with DOM
- c - Why I have error: deprecated conversion from string constant to 'char*' [-Wwrite-strings] in the line 5 and 6?
- facebook - Drupal 8 - 简单的 fb 连接失败
- excel - (Excel)如何在一个单元格中测试多个值?
- azure - 如何将 Azure Policy 与 Azure DevOps 集成?
- jenkins - 使用 SAML 在 Jenkins 中配置组授权
- c# - 如何为类的每个属性创建 lambda 表达式
- xml - Dynamics F&O - 无法为新销售订单导入 XML