Heroku部署的应用程序没有发送正确的响应,而如果我使用Heroku本地网站在本地运行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`));

软件包.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/

同时点击poster api req获得正确的响应

本地运行时的api请求

但当我点击已部署heroku应用程序的请求时,Getting error部署的Heroku应用

我看到了部署的heroku控制台上运行的内容,它似乎很好

网站上的控制台heroku

不确定问题出在哪里。请有人帮忙解决这个

最终解决了这个问题。

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

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

相关内容

最新更新