【问题标题】:How do I add a certifcate of a third party api to my app in Heroku?如何在 Heroku 中将第三方 api 的证书添加到我的应用程序中?
【发布时间】:2021-08-06 17:28:43
【问题描述】:

我的后端服务调用第三方 API (Kamer van koophandel) 来检索一些数据。但是这个 API 需要我设置一个证书。在本地它正在工作,但是当我将它推送到 Heroku 时,会发生以下错误:

Warning: Ignoring extra certs from `Private_G1_chain.pem`, load failed: error:02001002:system library:fopen:No such file or directory
   Warning: Ignoring extra certs from `Private_G1_chain.pem`, load failed: error:02001002:system library:fopen:No such file or directory
   Warning: Ignoring extra certs from `Private_G1_chain.pem`, load failed: error:02001002:system library:fopen:No such file or directory
   Warning: Ignoring extra certs from `Private_G1_chain.pem`, load failed: error:02001002:system library:fopen:No such file or directory
   gyp: Call to 'node -p "require('node-addon-api').include"' returned exit status 0 while in binding.gyp. while trying to load binding.gyp
   gyp ERR! configure error 
   gyp ERR! stack Error: `gyp` failed with exit code: 1
   gyp ERR! stack     at ChildProcess.onCpExit (/tmp/build_e15be358/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
   gyp ERR! stack     at ChildProcess.emit (events.js:376:20)
   gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
   gyp ERR! System Linux 4.4.0-1088-aws
   gyp ERR! command "/tmp/build_e15be358/.heroku/node/bin/node" "/tmp/build_e15be358/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/tmp/build_e15be358/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/tmp/build_e15be358/node_modules/bcrypt/lib/binding/napi-v3" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
   gyp ERR! cwd /tmp/build_e15be358/node_modules/bcrypt
   gyp ERR! node -v v14.17.0
   gyp ERR! node-gyp -v v5.1.0
   gyp ERR! not ok 
   node-pre-gyp ERR! build error 
   node-pre-gyp ERR! stack Error: Failed to execute '/tmp/build_e15be358/.heroku/node/bin/node /tmp/build_e15be358/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/tmp/build_e15be358/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node --module_name=bcrypt_lib --

在 Heroku 中,我设置了真正的配置变量: NODE_EXTRA_CA_CERTS = Private_G1_chain.pem

奇怪的是:如果我首先将我的应用程序推送到 Heroku,然后设置 NODE_EXTRA_CA_CERTS 它可以工作,但如果设置了 NODE_EXTRA_CA_CERTS 然后我将我的应用程序推送到 Heroku,我会收到上述错误..

顺便说一句,我的应用程序是内置的:node/express 并使用 typescript。

提前致谢!

【问题讨论】:

  • 也许是 heroku 上的一个错误。在 heroku 上创建另一个应用程序,然后重试。另一个测试可能是删除 heroku 仪表板中的 env var 并将其设置在代码的开头 process.env['NODE_EXTRA_CA_CERTS '] =Private_G1_chain.pem

标签: typescript express heroku server certificate


【解决方案1】:

Ignoring extra certs 错误是因为 Node 从您的 .pem 文件中获取了多个证书。 要解决该问题,您必须从 .pem 文件中删除空格和换行符。

为此,请按以下步骤操作:

awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' cert-name.pem

在您的证书文件所在的同一目录中运行此命令。该命令会在需要的地方简单地添加\n

你会得到类似这样的输出:

-----BEGIN RSA PRIVATE KEY-----\njlQvt9WdR9Vpg3WQT5+C3HU17bUOwvhp/r0+viMcBUCRW85UqI2BJJKTi1IwQQ4c\ntyTrhYJYOP+A6JXt5BzDzZy/B7tjEMDBosPiwH2m4MaP+6wTbi1qR1pFDL3fXYDr\n

在此之后将获得的字符串保存在.env 文件中,然后使用该参数而不是使用文件Private_G1_chain.pem

【讨论】:

    猜你喜欢
    • 2013-04-18
    • 2017-09-12
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 2016-11-16
    • 2013-08-13
    相关资源
    最近更新 更多