log headers
This commit is contained in:
parent
4249815c55
commit
3081b65f92
9
index.js
9
index.js
|
@ -59,8 +59,9 @@ global.wsConnections = [];
|
||||||
var roomList = [];
|
var roomList = [];
|
||||||
// IEM WebSocket
|
// IEM WebSocket
|
||||||
app.ws('/iem', (ws, req) => {
|
app.ws('/iem', (ws, req) => {
|
||||||
req.ip = process.env.REALIP ? req.headers[process.env.REALIP.toLowerCase()] : req.ip;
|
console.log(req.headers)
|
||||||
console.log(`connection from ${req.ip}`);
|
const clientIp = process.env.REALIP ? req.headers[process.env.REALIP.toLowerCase()] : req.ip;
|
||||||
|
console.log(`connection from ${clientIp}`);
|
||||||
const hostname = process.env.HOST_OVERRIDE || os.hostname();
|
const hostname = process.env.HOST_OVERRIDE || os.hostname();
|
||||||
|
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
|
@ -86,7 +87,7 @@ app.ws('/iem', (ws, req) => {
|
||||||
}));
|
}));
|
||||||
sock = wsConnections.push({ ws, req, subs: [] });
|
sock = wsConnections.push({ ws, req, subs: [] });
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
console.log(`disconnected from ${req.ip}`);
|
console.log(`disconnected from ${clientIp}`);
|
||||||
wsConnections = wsConnections.filter((conn) => conn.ws !== ws);
|
wsConnections = wsConnections.filter((conn) => conn.ws !== ws);
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
@ -102,7 +103,7 @@ app.ws('/iem', (ws, req) => {
|
||||||
"error": "Invalid JSON format."
|
"error": "Invalid JSON format."
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
console.log(`${colors.red("[ERROR]")} Invalid JSON format from ${req.ip}: ${msg}`);
|
console.log(`${colors.red("[ERROR]")} Invalid JSON format from ${clientIp}: ${msg}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!data.type) return ws.send(JSON.stringify({
|
if (!data.type) return ws.send(JSON.stringify({
|
||||||
|
|
Loading…
Reference in a new issue