I have this problem:
Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR
There was an error! TypeError: Failed to fetch
I'm trying to make https POST or GET request to the server
This problems happens only in Chrome browser (Firefox, postman works ok)
I made a simple server:
const express = require('express');
const cors = require('cors');
const fs = require('fs');
const https = require('https');
const bodyParser = require('body-parser');
const app = express();
// CORS middleware to allow cross-origin requests
app.use(cors());
// Parse JSON request body
app.use(bodyParser.json());
app.post('/hello_world', (req, res) => {
const { data } = req.body;
// Your logic...
res.status(200).send("Your response");
});
// SSL certificate
const options = {
key: fs.readFileSync('/etc/letsencrypt/live/myhostname.com/privkey.pem', 'utf8'),
cert: fs.readFileSync('/etc/letsencrypt/live/myhostname.com/cert.pem', 'utf8'),
ca: fs.readFileSync('/etc/letsencrypt/live/myhostname.com/chain.pem', 'utf8')
};
const httpsServer = https.createServer(options, app);
// Listen on either port 443 for https production server
httpsServer.listen(443, () => {
console.log('HTTPS Server running on port 443');
});
Request (frontend):
const response = await fetch("https://myhostname.com/hello_world", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({data: "123"}),
});
const rebus = await response.json();
Certificates created with:
certbot certonly -d myhostname.com
What could be the problem and how to understand the reason?
I tried other browsers (Firefox works well and postman also)