Clean up
This commit is contained in:
21
server.cjs
21
server.cjs
@@ -14,23 +14,6 @@ const pool = mariadb.createPool({
|
|||||||
connectionLimit: 5,
|
connectionLimit: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = {
|
|
||||||
port: 162,
|
|
||||||
disableAuthorization: true,
|
|
||||||
includeAuthentication: false,
|
|
||||||
accessControlModelType: snmp.AccessControlModelType.None,
|
|
||||||
address: null,
|
|
||||||
transport: "udp4",
|
|
||||||
};
|
|
||||||
|
|
||||||
const callback = (error, notification) => {
|
|
||||||
if (error) {
|
|
||||||
console.error(error);
|
|
||||||
} else {
|
|
||||||
console.log(notification);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function sqlEscape(str) {
|
function sqlEscape(str) {
|
||||||
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, (char) => {
|
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, (char) => {
|
||||||
switch (char) {
|
switch (char) {
|
||||||
@@ -58,8 +41,6 @@ function sqlEscape(str) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const receiver = snmp.createReceiver(options, callback);
|
|
||||||
|
|
||||||
// initializing app
|
// initializing app
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@@ -134,7 +115,7 @@ app.patch("/trigger/api/messages", async (req, res) => {
|
|||||||
|
|
||||||
app.delete("/trigger/api/messages", async (req, res) => {
|
app.delete("/trigger/api/messages", async (req, res) => {
|
||||||
const conn = await pool.getConnection();
|
const conn = await pool.getConnection();
|
||||||
const query = `DELETE FROM trigger_database.messages WHERE id = '${sqlEscape(req.body.id)}'`;
|
const query = `DELETE FROM trigger_database.messages WHERE id = '${req.body.id}'`;
|
||||||
conn
|
conn
|
||||||
.query(query)
|
.query(query)
|
||||||
.then((rows) => {
|
.then((rows) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user