I’m having trouble getting my local development setup to work with SSL certificates. My frontend is built with React and runs on port 3001, while my Node.js Express backend runs on port 3000.
Frontend Setup:
I can access my React app at https://localhost:3001 without issues when using SSL mode.
Backend Configuration:
My Express server uses custom SSL certificates:
const httpsOptions = {
key: fs.readFileSync('./ssl/private.key'),
cert: fs.readFileSync('./ssl/certificate.crt'),
ca: fs.readFileSync('./ssl/ca-bundle.crt')
};
https.createServer(httpsOptions, server).listen(serverPort, () => {
console.log(`Server running on port ${serverPort} with SSL enabled.`);
});
API Call from Frontend:
const apiResponse = await fetch('https://localhost:3000/api/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userData),
});
if (apiResponse.ok) {
console.log('Registration successful');
} else {
console.error('Registration failed');
}
CORS Configuration:
const corsConfig = {
origin: 'https://localhost:3001',
optionsSuccessStatus: 200,
};
server.use(cors(corsConfig));
The API works fine in Postman, but when called from the frontend I get CORS errors and network failures. Could this be related to certificate trust issues between the two services?