i am currently trying to make a raffle ticket system and need to write the ticket numbers to a sql database. However I keep getting an error about self signing certificates. I have downloaded the CA certificate and put its contents into a envelope variable. Everything works fine in development but in production I am getting the self signing certificate error. I am using vercel to host the Web app. Below is the error and the database config.
[nuxt] [request error] [unhandled] [500] self-signed certificate in certificate chain
at Object.createConnectionPromise [as createConnection] (./node_modules/mysql2/promise.js:18:31)
at Object.handler (./chunks/routes/api/webhook.mjs:60:34)
at Object.handler (./chunks/runtime.mjs:2837:24)
at Object.handler (./chunks/runtime.mjs:3146:34)
at Object.handler (./chunks/runtime.mjs:2908:31)
at async toNodeHandle (./chunks/runtime.mjs:3178:7)
at async Server.<anonymous> (/opt/rust/nodejs.js:9:6760)
const dbConfig={
host:process.env.MYSQL_HOST,
user:process.env.MYSQL_USER,
password:process.env.MYSQL_PASSWORD,
database:process.env.MYSQL_DATABASE,
port:process.env.MYSQL_PORT,
ssl:{
ca:process.env.CA_CERT,
}
};
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!
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.
Heya,
No an expert here but Try adjusting your
dbConfig
to addrejectUnauthorized: true
explicitly. This ensures strict verification.and make sure
CA_CERT
environment variable contains the full content of your downloaded CA certificate.Hi there,
You’ve already added the CA certificate to your environment variable, which is great! Now, you need to tweak your
ssl
configuration slightly to ensure Node.js trusts the certificate chain.Here’s the updated configuration for your
dbConfig
:Let me know how it goes!
- Bobby