Getting strapi working on digitalocean app plattform

Hi @rmartis and everyone else reading this,

I had a hard time as well figuring out how to connect the APP and Database on Digitalocean. Here’s what worked for me:

As @tw1t611 mentioned, the DATABASE_URL: ${<<yourDbName>>.DATABASE_URL} env variable doesn’t seem to work as we expect it at the moment. So setting the variable to the connection string is fixing this.
BUT: I figured out that DO sets the DATABASE_URL env automatically when you connect a database to the app.
In my case: These env variable is not shown in the Environment Variables section in the settings but in the config .yaml file (under a second envs key). In my case there where 3 DATABASE_URL variables because I changed connected DBs. I had to delete all of them to make my manually set DATABASE_URL (the connection string) env working again. Alternatively you can just name your variable differently.

In my code:
I had to install pg and pg-connection-string packages and add these code to my config/production/database.js:

const parse = require("pg-connection-string").parse;

const { host, port, database, user, password } = parse(
  process.env.DATABASE_URL
);
module.exports = () => ({
  connection: {
    client: "postgres",
    connection: {
      host,
      port,
      database,
      user,
      password,
      ssl: {
        rejectUnauthorized: false,
      },
    },
    debug: false,
  },
});


I’m not sure if these is the best way to do it but it worked out for me. Reach out if I should further clarify.

1 Like