简体   繁体   English

如何在节点JS服务器中包含根CA证书?

[英]How do I include a root CA certifciate in my node JS server?

I'm using npm v 5.7.1 on Mac High Sierra. 我在Mac High Sierra上使用npm v 5.7.1。 I just installed this module 我刚刚安装了这个模块

npm install ssl-root-cas

(for some reason, adding "-g" didn't work). (由于某种原因,添加“ -g”无效)。 Then i have this in my JS file 然后我的JS文件中有这个

require('ssl-root-cas')
    .inject()
    .addFile(fs.readFileSync(conf.root_cert));

However, upon executing the above code (specifically the "inject()" line), I get the error 但是,执行上面的代码(特别是“ inject()”行)后,我得到了错误

/Users/satishp/Documents/workspace/projA/node_modules/ssl-root-cas/ssl-root-cas.js:3637
  var filepaths = filepath.split(/\//g);
                           ^

TypeError: filepath.split is not a function
    at Array.module.exports.rootCas.addFile (/Users/satishp/Documents/workspace/projA/node_modules/ssl-root-cas/ssl-root-cas.js:3637:28)
    at Object.<anonymous> (/Users/satishp/Documents/workspace/projA/server.js:79:3)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:660:3

I'm somewhat confused about how to proceed. 我对如何进行感到有些困惑。 How do I overcome this error? 如何克服这个错误?

You just need to pass the file path for the addFile function, no need to manually load the file content: 您只需要传递addFile函数的文件路径,而无需手动加载文件内容:

require('ssl-root-cas')
  .inject()
  .addFile(conf.root_cert);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM