ERROR: self-signed certificate in certificate chain in NextJS 14

152 views Asked by At

I'm using NextJS 14.0.4 to connect with my planetscale database using mysql2 package. The connection worked fine when my database secrets were hard coded. When I placed my secrets in .env.local file. The localhost gives error "Error: self-signed certificate in certificate chain". Although it still works fine on my vercel deployment.

I already tried adding --experimental-https to my dev script and install the mkcert certificates following this solution yet the issue still persists. My database connection code

const pool = mysql.createPool({
    host: process.env.NEXT_PUBLIC_HOST,
    user: process.env.NEXT_PUBLIC_USERNAME,
    database: process.env.NEXT_PUBLIC_DATABASE,
    password: process.env.NEXT_PUBLIC_PASSWORD,
    waitForConnections: true,
    connectionLimit: 10,
    maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`
    idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000
    queueLimit: 0,
    enableKeepAlive: true,
    keepAliveInitialDelay: 0,
    ssl: {
        rejectUnauthorized: true,
    },
})

I need to keep ssle rejectUnauthorized: true as it is required by planetscale.

0

There are 0 answers