vendredi 18 décembre 2020

Site throwing ERR_CONNECTION_TIMED_OUT after refreshing or loading another page

I just got my SSL working and am just testing and working on my site and hosting on my PC. I am having issues with the loading of the site. It seems to work normal for a bit, but at closer inspection, after a while of sitting or after refreshing I get ERR_CONNECTION_TIMED_OUT. Not sure why. (I could leave and try navigating to a seperate page ERR_CONNECTION_TIMED_OUT. Just simply refreshing causes it sometimes, while others it just works perfect.

const path = require('path'),
    https = require('https'),
    http = require('http'),
    fs = require('fs'),
    express = require('express'),
    socketio = require('socket.io'),
    e = require('express'),
    { isObject } = require('util'),
    { fstat } = require('fs'),
    { forceDomain } = require('forcedomain');

var options = {
    key: fs.readFileSync(__dirname+'/ssl/privkey.pem'),
    cert: fs.readFileSync(__dirname+'/ssl/cert.pem')
};

const app = express();
const server = https.createServer(options, app);
const io = socketio(server);

// Set static folder
app.use(express.static('public', { dotfiles: 'allow'}));

const PORT = process.env.PORT || 443,
    httpPort = process.env.PORT || 80;

server.listen(PORT, "0.0.0.0", () => console.log(`Server running on port ${PORT}`));

var httpSer = express();

httpSer.get('*', function(req, res) {  
    res.redirect('https://' + req.headers.host + req.url);
});

httpSer.listen(httpPort, "0.0.0.0", () => console.log(`Server running on port ${httpPort}`));

What could be causing this to happen?




Aucun commentaire:

Enregistrer un commentaire