При таком подходе, пропадает необходимость использовать app.get(), так как все файлы и так будут отданы. Плюс, смущает факт того, что доступ к файлам можно получить прописав путь напрямую /home/index.html
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var fs = require('fs');
var https = require('https');
app.set('views', __dirname + '/views')
app.set('view engine', 'pug')
app.use(express.static(__dirname + '/public'))
server.listen(5000, function () {
console.log('Server listening at port %d', 5000);
});
const opts = {
key: fs.readFileSync('privateKey.key'),
cert: fs.readFileSync('certificate.crt')
}
var httpsServer = https.createServer(opts, app);
httpsServer.listen(5001, function(){
console.log("HTTPS on port " + 5001);
})
app.get('/', function (req, res) {
res.render('index');
})
io.attach(httpsServer);
io.attach(server);
io.on('connection', function(client) {
console.log('Client connected...');
client.on('click', function(data){
console.log(JSON.parse(data));
setTimeout(function() {
client.emit("ok", "data");
}, 3000);
})
});
if (window.location.protocol != "https:"){
var socket = io.connect('https://localhost:5001');
} else {
var socket = io.connect('http://localhost:5000');
}
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Authorization"]
setInterval(function () {
let startTime = process.hrtime.bigint();
connection.query('SELECT * FROM drops ORDER BY id DESC LIMIT 10', function (error, result, fields) {
socket.emit('games', result);
});
let endTime = process.hrtime.bigint();
console.log("DB Req1: " + (endTime - startTime)); // in nanosec.
}, 2000);
var app = new Vue({
el: '#app',
data: function() {
return {
msg: 'Hello World! This is a Event listener test.',
windowWidth: 0,
windowHeight: 0,
}
},
mounted() {
this.$nextTick(function() {
window.addEventListener('resize', this.getWindowWidth);
window.addEventListener('resize', this.getWindowHeight);
//Init
this.getWindowWidth()
this.getWindowHeight()
})
},
methods: {
getWindowWidth(event) {
this.windowWidth = document.documentElement.clientWidth;
},
getWindowHeight(event) {
this.windowHeight = document.documentElement.clientHeight;
}
},
beforeDestroy() {
window.removeEventListener('resize', this.getWindowWidth);
window.removeEventListener('resize', this.getWindowHeight);
}
});
var child = require('child_process').execFile;
var executablePath = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
child(executablePath, function(err, data) {
if(err){
console.error(err);
return;
}
console.log(data.toString());
});
socket.emit('getUserInfo')
io = require('socket.io').listen(httpsServer);
io.on('connection', function(socket) {
socket.on('getUserInfo', function(e) {
//code
...
socket.emit('sendUserInfo', data)
})
});