Hi,,
I am getting a 500 runtime error on my webapp made with Nextjs (v14.2.16) + drizzle-kit & drizzle-orm + /postgres running on Supabase DB.
Here's the stack trace:
Unexpected error: Error: self-signed certificate in certificate chain at /var/task/node_modules/pg-pool/index.js:45:11 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async /var/task/.next/server/chunks/749.js:7:34868 at async c (/var/task/.next/server/app/api/survey/[slug]/route.js:1:899) at async /var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:37010 at async eC.execute (/var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:27552) at async eC.handle (/var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:38344) at async es (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:16:25262) at async en.responseCache.get.routeKind (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:1026) at async r6.renderToResponseWithComponentsImpl (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:508) { code: 'SELF_SIGNED_CERT_IN_CHAIN'
<!-- Current versus Expected behavior -->I've tried to use this as per recommendation from cursor but no success:
const pool = new Pool({ connectionString: process.env.POSTGRES_URL, ssl: { rejectUnauthorized: false, // This allows self-signed certificates },});I've also tried the fix as per discussion here https://github.com/drizzle-team/drizzle-orm/discussions/881
This is my drizzle.config.js:
import 'dotenv/config';import { defineConfig } from 'drizzle-kit';
if (!process.env.POSTGRES_URL) { throw new Error('POSTGRES_URL environment variable is required');}
if (!process.env.DATABASE_CA) { throw new Error('DATABASE_CA environment variable is required');}
export default defineConfig({ out: './db/migrations', schema: './db/schema.ts', dialect: 'postgresql', dbCredentials: { // url: `${process.env.POSTGRES_URL!}?sslmode=no-verify`, url: process.env.POSTGRES_URL!, ssl: { ca: process.env.DATABASE_CA }, },});and this is how I connect to PostgreSQL:
// Create a PostgreSQL pool using connection string from environment variablesconst pool = new Pool({ connectionString: process.env.POSTGRES_URL, ssl: { rejectUnauthorized: false, // This allows self-signed certificates },});const db = drizzle(pool, { schema });