I
I
Igor Myasnikov2020-01-14 09:53:45
Node.js
Igor Myasnikov, 2020-01-14 09:53:45

How to fix error when deploying Strapi to Heroku?

Good afternoon!
Error when connecting to Mongo Atlas DB on Heroku

Connection error

2020-01-14T06:45:45.473Z] debug ⛔ Server wasn't able to start properly.
2020-01-14T06:45:45.474867+00:00 app[web.1]: [2020-01-14T06:45:45.474Z] error Error connecting to the Mongo database. Server selection timed out after 30000 ms


When run locally, everything works!
production/database settings

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "mongoose",
      "settings": {
        "host": "${process.env.DATABASE_HOST || '127.0.0.1'}",
        "port": "${process.env.DATABASE_PORT || 27017}",
        "database": "${process.env.DATABASE_NAME || 'strapi'}",
        "username": "${process.env.DATABASE_USERNAME || ''}",
        "password": "${process.env.DATABASE_PASSWORD || ''}"
      },
      "options": {}
    }
  }
}


Registered the connection and through uri - the same result
production/database settings

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "mongoose",
      "settings": {
        "uri": "${process.env.DATABASE_URI}",
        "database": "${process.env.DATABASE_NAME}"
      },
      "options": {
        "ssl": true
      }
    }
  }
}


Everything is written in the config vars of Heroku
Access to the database is open

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2020-01-14
@pilium

What command of start checked locally? heroku local?
Does it show the heroku configcorrect variable values DATABASE_?
Accordingly, not localhost...

V
Vladislav Bondarenko, 2020-05-08
@bvlad5

This fix helped me:
https://github.com/strapi/strapi/pull/6027/commits...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question