I'm trying to make an HTTPS request to my Node.js server using Axios, but I keep getting the ERR_SSL_PROTOCOL_ERROR error. I've verified that my SSL/TLS certificate files are valid and that my server is configured to use HTTPS, but I still can't seem to make a successful request. Here's my Node.js code:
const express = require("express");
const mysql = require('mysql');
const cors = require('cors');
const fs = require('fs');
const https = require('https');
const app = express();
app.use(cors());
app.use(express.json());
// Middleware to handle CORS
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', 'https://mydomain(dot)com');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
const db = mysql.createPool({
host: "123.456.789.012",
user: "myuser",
port: "3306",
password: "mypassword",
database: "mydb",
ssl: {
ca: fs.readFileSync('/path/to/ca.crt'),
key: fs.readFileSync('/path/to/private-key.pem'),
cert: fs.readFileSync('/path/to/certificate.pem')
}
});
// Handle database connection errors
db.query('SELECT 1 + 1 AS solution', (error, results) => {
if (error) {
console.error('Error connecting to MySQL:', error);
process.exit(1); // Terminate the application on database connection failure
} else {
console.log('Connected to MySQL. Result:', results[0].solution);
}
});
// ... other routes and handlers
const PORT = 8081;
const options = {
key: fs.readFileSync('/path/to/private-key.pem'),
cert: fs.readFileSync('/path/to/certificate.pem'),
ciphers: 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA'
};
https.createServer(options, app).listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
I tried having an ssl certificate on my database but nothing happens. I am a beginner at this, I honestly have no idea on what I should do and there seems to be no solution online. I am considering to remove my certbot configuration entirely to return back my website into http and start again. I dont know if my ssl configuration or certificate is wrong or just my backend