root@noderelay:/opt/bc-relay# cat ecosystem.yml
apps:
- script: /opt/bc-relay/index.js
name: "app"
max_memory_restart: '500M'
exec_mode: "cluster"
let noft = await vk.call('messages.getConversationMembers', {
peer_id: msg.message.peer_id,
fields: 'id, first_name',
group_id: 193658885
});
noft.items.forEach(element => {
if (element.member_id > 0){
console.log("[id" + element.member_id.join('') + '|@]')
// messagesend('[id' + element.member_id + '|@]')
}
});
socket.on('connect', function () {
socket.emit('join', {email: user@example.com});
});
io.on('connection', function (socket) {
socket.on('join', function (data) {
socket.join(data.email);
});
});
io.to('user@example.com').emit('message', {msg: 'hello world.'});
socket.on("message", function(data) {
alert(data.msg);
});
function docker_tag_exists() {
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
}
if docker_tag_exists library/nginx 1.7.5; then
echo exist
else
echo not exists
fi
const http = require('http');
const fs = require('fs');
const file = fs.createWriteStream("file.jpg");
const request = http.get("http://test.ru/text.txt ", function(response) {
response.pipe(file);
});
const http = require('http');
var downFile = "";
const request = http.get("http://test.ru/text.txt ", function(response) {
downFile(response);
});
При таком подходе, пропадает необходимость использовать 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);