I’m new to Stack Overflow and this is my first question, so please bear with me. I never had to ask a question until I had a problem and couldn’t find a solution. Anyways, my problem is my Node JS HTTPS server that I use to host my website has a problem where when the client requests a resource such as a video or an image, it’s a 50% chance that the resource will properly load for the client. The times it doesn’t load I get an SSL error in the console (for example, net::ERR_SSL_PROTOCOL_ERROR 200 (OK)). Sometimes it will load, sometimes it won’t. I don’t know if I have a misconfiguration with my server or not, but I need to get this fixed. I need the resource to load for the client 100% of the time. Any help would be great.
Here’s how my server is configured.
// Redirect HTTP traffic to HTTPS
http.createServer((req, res) => {
if (req.headers.host === 'domain.com') {
let redirectUrl = `https://${req.headers.host}${req.url}`;
res.statusCode = 301;
res.setHeader('Location', redirectUrl);
res.end();
return;
}
reqHandler(req, res);
}).listen(80);
// HTTPS server
const server = https.createServer({
cert: readFileSync('/path/to/cert.pem').toString(),
key: readFileSync('/path/to/key.pem').toString(),
ca: readFileSync('/path/to/chain.pem').toString()
}, reqHandler);
server.listen(443);