因此,我已经完全关注Strapi和Heroku的文档(MongoDb Atlas已连接到Strapi),我可能错过了一些重要的东西。当我部署应用程序时,网站加载了一段时间,然后崩溃了。 heroku logs --tail
命令显示以下内容:
2020-05-08T14:41:59.625984+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
2020-05-08T14:41:59.626067+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
2020-05-08T14:41:59.626134+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
2020-05-08T14:42:04.000000+00:00 app[api]: Build succeeded
2020-05-08T14:42:29.627137+00:00 app[web.1]: [2020-05-08T14:42:29.626Z] debug ⛔️ Server wasn't able to start properly.
2020-05-08T14:42:29.627879+00:00 app[web.1]: [2020-05-08T14:42:29.627Z] error Error connecting to the Mongo database. Server selection timed out after 30000 ms
2020-05-08T14:42:29.640717+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-08T14:42:29.640989+00:00 app[web.1]: npm ERR! errno 1
2020-05-08T14:42:29.641812+00:00 app[web.1]: npm ERR! back-end-4@0.1.0 start: `strapi start`
2020-05-08T14:42:29.641895+00:00 app[web.1]: npm ERR! Exit status 1
2020-05-08T14:42:29.641997+00:00 app[web.1]: npm ERR!
2020-05-08T14:42:29.642078+00:00 app[web.1]: npm ERR! Failed at the back-end-4@0.1.0 start script.
2020-05-08T14:42:29.642155+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-08T14:42:29.649687+00:00 app[web.1]:
2020-05-08T14:42:29.649822+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-05-08T14:42:29.649879+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-05-08T14_42_29_643Z-debug.log
2020-05-08T14:42:29.758124+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-08T14:42:30.872518+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hidden-headland-71392.herokuapp.com request_id=2eb6e39a-875b-4b2c-91cd-3b2bdd914561 fwd="81.128.178.133" dyno= connect= service= status=503 bytes= protocol=https
2020-05-08T14:42:31.888706+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hidden-headland-71392.herokuapp.com request_id=d96ec78a-83ea-48ca-b576-0ad62d0a15da fwd="81.128.178.133" dyno= connect= service= status=503 bytes= protocol=https
所有3个文件夹,开发,生产和暂存中的server.json文件如下:
{
"host": "${process.env.HOST || '0.0.0.0'}",
"port": "${process.env.PORT || 1337}",
"production": true,
"proxy": {
"enabled": false
},
"cron": {
"enabled": false
},
"admin": {
"autoOpen": false
}
}
我不确定Procfile,因为它位于我的基本目录中,没有扩展名,但带有以下行:
web: node strapi start
我的package.json
像这样:
{
"name": "back-end-4",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
我的database.json
文件看起来像这样:
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "mongoose",
"settings": {
"uri": "${process.env.DATABASE_URI}",
"database": "${process.env.DATABASE_NAME}"
},
"options": {
"ssl": true
}
}
}
}
答案 0 :(得分:1)
这里是一个视频,用于使用Heroku + MongoDB Atlas部署Strapi应用程序
https://www.youtube.com/watch?v=HHnRsZwFmR8&list=PL7Q0DQYATmvhlHxHqfKHsr-zFls2mIVTi&index=11&t=0s
答案 1 :(得分:1)
FWIW-我有类似的问题。我以为我已经将Mongodb上的所有IP列入了白名单,但没有。上面提到的视频中不包含此步骤,并且-根据记录到控制台的输出-我猜您遇到了同样的问题。
可以在Mongodb的“安全性”>“网络访问”>“添加IP地址”下找到此设置。如果使用0.0.0.0/0
,它将把Heroku抛出的所有内容列入白名单。
答案 2 :(得分:0)
我遇到了同样的问题,我必须确保三件事:
npm install
,使用heroku logs --tail
仔细检查我的部署日志bu,以查看是否还缺少任何依赖项。检查了所有这些内容之后,我终于设法部署了我的应用程序。
答案 3 :(得分:-1)
我没有使用Heroku,但我想可以共享我的database.json。也许您可以尝试一下,看看会发生什么。
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "mongoose",
"settings": {
"uri": "mongodb://localhost:27017/mydatabase",
"database": "mydatabase",
"host": "127.0.0.1",
"srv": false,
"port": 27017,
"username": "myusername",
"password": "mypassword"
},
"options": {
"ssl": false
}
}
}
}