By Carter Todd
Mr
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!
Heya,
No an expert here but Try adjusting your dbConfig
to add rejectUnauthorized: true
explicitly. This ensures strict verification.
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, // Your CA certificate content
rejectUnauthorized: true, // Ensures the client validates the server's certificate
},
};
and make sure CA_CERT
environment variable contains the full content of your downloaded CA certificate.
export CA_CERT=$(cat /path/to/ca-certificate.pem)
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
:
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: {
rejectUnauthorized: true,
ca: process.env.CA_CERT,
},
};
Let me know how it goes!
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.