Fixed CORS issue and added chat spam safeguard
This commit is contained in:
parent
b4e9c67be5
commit
f1e70f7763
@ -16,6 +16,13 @@ var ns = {
|
|||||||
tanks: io.of("/tanks")
|
tanks: io.of("/tanks")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Allow CORS from ARNweb.nl
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
res.header("Access-Control-Allow-Origin", "https://arnweb.nl");
|
||||||
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Request documentation
|
// Request documentation
|
||||||
app.get("/", (req, res) =>
|
app.get("/", (req, res) =>
|
||||||
res.status(200).sendFile(path.resolve(__dirname + "/../html/index.html"))
|
res.status(200).sendFile(path.resolve(__dirname + "/../html/index.html"))
|
||||||
|
@ -38,20 +38,22 @@ function handle(io, socket) {
|
|||||||
|
|
||||||
// Handle messages
|
// Handle messages
|
||||||
socket.on("message_send", function (message) {
|
socket.on("message_send", function (message) {
|
||||||
// Build message data for clients
|
if (socket.username) {
|
||||||
message = striptags(message, "<br />");
|
// Build message data for clients
|
||||||
if (message !== "") {
|
message = striptags(message, "<br />");
|
||||||
message = md.render(message);
|
if (message !== "") {
|
||||||
message = message.replace(/\r?\n/g, "<br />");
|
message = md.render(message);
|
||||||
var msg = {
|
message = message.replace(/\r?\n/g, "<br />");
|
||||||
"username": socket.username,
|
var msg = {
|
||||||
"mailHash": socket.mailHash,
|
"username": socket.username,
|
||||||
"message": message
|
"mailHash": socket.mailHash,
|
||||||
};
|
"message": message
|
||||||
// Send message to clients
|
};
|
||||||
io.emit("message_receive", msg);
|
// Send message to clients
|
||||||
} else {
|
io.emit("message_receive", msg);
|
||||||
socket.emit("message_receive", serverMsg("Empty messages will not be sent."));
|
} else {
|
||||||
|
socket.emit("message_receive", serverMsg("Empty messages will not be sent."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user