【发布时间】:2019-07-04 10:32:38
【问题描述】:
我知道这已被问过几次,但我还没有找到可行的解决方案。我正在尝试将我的节点服务器部署在 Heroku 上并构建成功,但日志会打印以下消息。我也在使用猫鼬,本地部署没有问题。
2019-02-10T22:30:09.912634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=chatifydotcom.herokuapp.com request_id=b486e511-ff21-4166-ae1d-07bf5796691e fwd="74.196.2.211" dyno= connect= service= status=503 bytes= protocol=https
2019-02-10T22:30:10.287542+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=chatifydotcom.herokuapp. com request_id=18f17ca0-56df-4dfe-a560-d890a699f17f fwd="74.196.2.211" dyno= connect= service= status=503 bytes= protocol=https
服务器.js
const uri = process.env.MONGODB_URI || "mongodb://localhost:27017/chat"
mongoose
.connect(uri, { useNewUrlParser: true })
.then(() => console.log("MongoDB Connected"))
.catch(err => console.log(err.message))
const port = process.env.PORT || 9000
server.listen(port, () => {
console.log(`This server is over ${port}`)
})
【问题讨论】: