Question

How to access Managed DB from App (Express API application using Knex to Postgres DB)

Posted May 21, 2021 276 views
Node.jsPostgreSQLConfiguration ManagementDigitalOcean Managed PostgreSQL DatabaseDigitalOcean App Platform

I deployed an Express API application (Node) that is building and deploying successfully on the App Platform. However, when I connected my managed Postgres DB (NO trusted source - completely open to public) and try to hit one of my endpoints that queries data I am getting a Error: self signed certificate in certificate chain error.

I am using Knex to connect to my database using the following config file:

module.exports = {
    development: {
        client: 'pg',
        connection: process.env.DATABASE_URL,
        ssl: {
            require: true,
            rejectUnauthorized: false,
            ca: process.env.CA_CERT
        },
        debug: true
    },
    production: {
        client: 'pg',
        connection: process.env.DATABASE_URL,
        ssl: {
            require: true,
            rejectUnauthorized: false,
            ca: process.env.CA_CERT
        },
        debug: false
    }
};

In my API application settings, I am passing both Key Value pairs as environment variables:
DATABASEURL -> ${db-postgresql-sfo2.DATABASEURL}
CACERT -> ${db-postgresql-sfo2.CACERT}

Even with this configuration, I am still getting the certificate error.

Can someone please provide some guidance here!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer