Question

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

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: DATABASE_URL -> ${db-postgresql-sfo2.DATABASE_URL} CA_CERT -> ${db-postgresql-sfo2.CA_CERT}

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

Can someone please provide some guidance here!

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Hi @milanShrimp,

Found a similar question answered in our community Q&A.

https://www.digitalocean.com/community/questions/can-t-connect-to-managed-database-self_signed_cert_in_chain-error

Hope this helps.

Regards, Rajkishore