[英]Heroku deployed app is not sending proper response while if I run heroku locally using heroku local web , I am getting proper response
I am trying to deploy a node+express+mongo into heroku.我正在尝试将 node+express+mongo 部署到 heroku 中。
index.js 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 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"
}
}
Now I am trying to run the node using local heroku using heroku local web现在我正在尝试使用本地 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/
while hitting the postman api req getting proper response同时击中 postman api req 得到正确响应
api req when running locally本地运行时的 api req
But when I hit request for the deployed heroku app, Getting error Deployed Heroku app但是当我点击部署的 heroku 应用程序的请求时,出现错误Deployed Heroku 应用程序
I saw what is running on console of deployed heroku, it seems fine我看到部署的 heroku 的控制台上正在运行什么,看起来不错
Console on web heroku web heroku 上的控制台
Not sure what the problem is.不确定是什么问题。 someone please help to solve this有人请帮忙解决这个问题
Finally figurred out the problem.终于弄清楚了问题所在。
I am sending request via https:// which is not supported我通过不支持的 https:// 发送请求
changed my request url to http://... http://immense-sands-26614.herokuapp.com/api/movies将我的请求 url 更改为 http://... http://immense-sands-26614.herokuapp.com/api/movies
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.