程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用 node.js 和 postgresql api 部署 Heroku 不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决使用 node.js 和 POSTGResql api 部署 Heroku 不起作用?

开发过程中遇到使用 node.js 和 POSTGResql api 部署 Heroku 不起作用的问题如何解决?下面主要结合日常开发的经验,给出你关于使用 node.js 和 POSTGResql api 部署 Heroku 不起作用的解决方法建议,希望对你解决使用 node.js 和 POSTGResql api 部署 Heroku 不起作用有所启发或帮助;

我最近一直在研究带有存储书籍的 POSTGResql 数据库的 node.Js API。 当您转到路线 /books 时,它会给我 Heroku 应用程序错误页面(这里是 API https://node-api-with-books.herokuapp.com/books),我按照本教程制作了它 https://www.taniarascia.com/node-express-POSTGResql-heroku/。它让我发疯,这是我这样做时出现的错误:

heroku logs --tail
2021-03-15T04:04:21.094893+00:00 app[web.1]: /app/index.Js:12
2021-03-15T04:04:21.094902+00:00 app[web.1]: throw err;
2021-03-15T04:04:21.094903+00:00 app[web.1]: ^
2021-03-15T04:04:21.094904+00:00 app[web.1]: 
2021-03-15T04:04:21.094904+00:00 app[web.1]: Error: self signed certificate
2021-03-15T04:04:21.094905+00:00 app[web.1]: at TLSSocket.onConnectSecure (node:_tls_wrap:1498:34)
2021-03-15T04:04:21.094906+00:00 app[web.1]: at TLSSocket.emit (node:events:327:20)
2021-03-15T04:04:21.094906+00:00 app[web.1]: at TLSSocket._finishInit (node:_tls_wrap:933:8)
2021-03-15T04:04:21.094907+00:00 app[web.1]: at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:707:12) {
2021-03-15T04:04:21.094907+00:00 app[web.1]: code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
2021-03-15T04:04:21.094907+00:00 app[web.1]: }
2021-03-15T04:04:21.099759+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/books" host=node-API-with-books.herokuapp.com request_ID=5ec4a052-1aed-4401-916d-1699f1fe9d3d fwd="66.7.125.54" dyno=web.1 connect=0ms service=50ms status=503 bytes=0 protocol=https
2021-03-15T04:04:21.100313+00:00 app[web.1]: npm notice
2021-03-15T04:04:21.100365+00:00 app[web.1]: npm notice New minor version of npm available! 7.0.8 -> 7.6.3
2021-03-15T04:04:21.100444+00:00 app[web.1]: npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.6.3>
2021-03-15T04:04:21.100541+00:00 app[web.1]: npm notice Run `npm install -g npm@7.6.3` to update!
2021-03-15T04:04:21.100619+00:00 app[web.1]: npm notice
2021-03-15T04:04:21.104741+00:00 app[web.1]: npm ERR! code 1
2021-03-15T04:04:21.104926+00:00 app[web.1]: npm ERR! path /app
2021-03-15T04:04:21.108208+00:00 app[web.1]: npm ERR! command Failed
2021-03-15T04:04:21.108390+00:00 app[web.1]: npm ERR! command sh -c node index.Js
2021-03-15T04:04:21.353877+00:00 app[web.1]: 
2021-03-15T04:04:21.354099+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-03-15T04:04:21.354257+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-03-15T04_04_21_109Z-deBUG.log
2021-03-15T04:04:21.413929+00:00 heroku[web.1]: Process exited with status 1
2021-03-15T04:04:21.490613+00:00 heroku[web.1]: State changed from up to crashed
2021-03-15T04:04:21.495328+00:00 heroku[web.1]: State changed from crashed to starTing
2021-03-15T04:04:24.629509+00:00 heroku[web.1]: StarTing process with command `npm start`
2021-03-15T04:04:27.698683+00:00 app[web.1]: 
2021-03-15T04:04:27.698698+00:00 app[web.1]: > working-rest-API@1.0.0 start
2021-03-15T04:04:27.698698+00:00 app[web.1]: > node index.Js
2021-03-15T04:04:27.698698+00:00 app[web.1]: 
2021-03-15T04:04:28.035756+00:00 app[web.1]: Server Listening
2021-03-15T04:04:28.553149+00:00 heroku[web.1]: State changed from starTing to up
2021-03-15T04:04:29.332623+00:00 app[web.1]: /app/index.Js:12
2021-03-15T04:04:29.332639+00:00 app[web.1]: throw err;
2021-03-15T04:04:29.332640+00:00 app[web.1]: ^
2021-03-15T04:04:29.332641+00:00 app[web.1]: 
2021-03-15T04:04:29.332641+00:00 app[web.1]: Error: self signed certificate
2021-03-15T04:04:29.332642+00:00 app[web.1]: at TLSSocket.onConnectSecure (node:_tls_wrap:1498:34)
2021-03-15T04:04:29.332643+00:00 app[web.1]: at TLSSocket.emit (node:events:327:20)
2021-03-15T04:04:29.332643+00:00 app[web.1]: at TLSSocket._finishInit (node:_tls_wrap:933:8)
2021-03-15T04:04:29.332643+00:00 app[web.1]: at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:707:12) {
2021-03-15T04:04:29.332644+00:00 app[web.1]: code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
2021-03-15T04:04:29.332644+00:00 app[web.1]: }
2021-03-15T04:04:29.340112+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/books" host=node-API-with-books.herokuapp.com request_ID=8af9f82c-42c9-4399-9de3-ed80f7dee15a fwd="66.7.125.54" dyno=web.1 connect=1ms service=74ms status=503 bytes=0 protocol=https
2021-03-15T04:04:29.343368+00:00 app[web.1]: npm notice
2021-03-15T04:04:29.343566+00:00 app[web.1]: npm notice New minor version of npm available! 7.0.8 -> 7.6.3
2021-03-15T04:04:29.343688+00:00 app[web.1]: npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.6.3>
2021-03-15T04:04:29.343859+00:00 app[web.1]: npm notice Run `npm install -g npm@7.6.3` to update!
2021-03-15T04:04:29.344058+00:00 app[web.1]: npm notice
2021-03-15T04:04:29.348863+00:00 app[web.1]: npm ERR! code 1
2021-03-15T04:04:29.349087+00:00 app[web.1]: npm ERR! path /app
2021-03-15T04:04:29.352585+00:00 app[web.1]: npm ERR! command Failed
2021-03-15T04:04:29.352766+00:00 app[web.1]: npm ERR! command sh -c node index.Js
2021-03-15T04:04:29.364318+00:00 app[web.1]: 
2021-03-15T04:04:29.364464+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-03-15T04:04:29.364515+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-03-15T04_04_29_354Z-deBUG.log
2021-03-15T04:04:29.443525+00:00 heroku[web.1]: Process exited with status 1
2021-03-15T04:04:29.510747+00:00 heroku[web.1]: State changed from up to crashed

如果你有想法我可以加你到heroku 这是我在 github 上的代码 https://github.com/PugmanD/gticlicker-api-and-book-api/tree/main

感谢任何帮助

解决方法

尝试使用上传的存储库后。我已经确认错误出在以下位置

config.js

const pool = new Pool({
    connectionString: isProduction ? process.env.DATABASE_URL : connectionString,ssl: isProduction,// The problem is this setTing
});

更新您的 config.js 以关注

const pool = new Pool({
  connectionString: isProduction ? process.env.DATABASE_URL : connectionString,ssl: {
    rejectUnauthorized: false,},});

node-POSTGRes 确实在他们的文档中展示了如何设置 SSL https://node-POSTGRes.com/features/ssl

遇到这个问题的原因很可能是 node-POSTGRes 找不到你的 SSL 证书,因此出现了错误。

这是我使它工作的 heroku 链接,我将在几天内删除该项目。随意尝试一下。 https://test-POSTGResl.herokuapp.com/books

大佬总结

以上是大佬教程为你收集整理的使用 node.js 和 postgresql api 部署 Heroku 不起作用全部内容,希望文章能够帮你解决使用 node.js 和 postgresql api 部署 Heroku 不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。