程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Heroku 部署的应用程序没有发送正确的响应,而如果我使用 heroku local web 在本地运行 heroku,我会得到正确的响应大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Heroku 部署的应用程序没有发送正确的响应,而如果我使用 heroku local web 在本地运行 heroku,我会得到正确的响应?

开发过程中遇到Heroku 部署的应用程序没有发送正确的响应,而如果我使用 heroku local web 在本地运行 heroku,我会得到正确的响应的问题如何解决?下面主要结合日常开发的经验,给出你关于Heroku 部署的应用程序没有发送正确的响应,而如果我使用 heroku local web 在本地运行 heroku,我会得到正确的响应的解决方法建议,希望对你解决Heroku 部署的应用程序没有发送正确的响应,而如果我使用 heroku local web 在本地运行 heroku,我会得到正确的响应有所启发或帮助;

我正在尝试将 node+express+mongo 部署到 heroku。

index.Js

const PORT = process.env.PORT || 3200;

const cONNECTION_URL =
  "mongodb+srv://aarthi:C<password>@cluster0.prt4u.mongodb.net/BookMyShow?retryWrites=true&w=majority";

mongoose
  .connect(CONNECTION_URL,{ useNewUrlParser: true,useUnifIEdtopology: true })
  .then(() =>
    app.Listen(PORT,() =>
      console.log(
        `Server Running on Port:https://immense-sands-26614.herokuapp.com/`
      )
    )
  )
  .catch((error) => console.log(`${error} dID not connect`));

package.Json

{
  "name": "Hackathon_server","version": "1.0.0","description": "","main": "index.Js","type": "module","scripts": {
    "test": "echo \"Error: no test specifIEd\" && exit 1","start": "nodemon index.Js"
  },"keywords": [
    "example","heroku"
  ],"author": "","license": "ISC","dependencIEs": {
    "cors": "^2.8.5","express": "^4.17.1","mongodb": "^3.6.6","mongoose": "^5.12.3","nodemon": "^2.0.7","valIDator": "^13.5.2"
  },"ENGInes": {
    "node": "14.15.1"
  }
}

现在我正在尝试使用本地 heroku 使用 heroku 本地 web 运行节点

:47:13 pm web.1 |  [nodemon] 2.0.7
4:47:13 pm web.1 |  [nodemon] to restart at any time,enter `rs`
4:47:13 pm web.1 |  [nodemon] watching path(s): *.*
4:47:13 pm web.1 |  [nodemon] watching extensions: Js,mJs,Json
4:47:13 pm web.1 |  [nodemon] starTing `node index.Js`
4:47:17 pm web.1 |  (node:33016) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
4:47:17 pm web.1 |  (Use `node --trace-deprecation ...` to show where the warning was created)
4:47:17 pm web.1 |  Server Running on Port:https://immense-sands-26614.herokuapp.com/

同时点击 postman API req 获得正确响应

api req when running locally

但是当我点击已部署的 heroku 应用程序的请求时,出现错误 Deployed Heroku app

我看到了在已部署的 heroku 控制台上运行的内容,看起来不错

Console on web heroku

不知道是什么问题。有人请帮忙解决这个问题

解决方法

终于解决了问题。

我通过不支持的 https:// 发送请求

将我的请求 url 更改为 http://... http://immense-sands-26614.herokuapp.com/api/movies

大佬总结

以上是大佬教程为你收集整理的Heroku 部署的应用程序没有发送正确的响应,而如果我使用 heroku local web 在本地运行 heroku,我会得到正确的响应全部内容,希望文章能够帮你解决Heroku 部署的应用程序没有发送正确的响应,而如果我使用 heroku local web 在本地运行 heroku,我会得到正确的响应所遇到的程序开发问题。

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

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