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!


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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