bodge to try and patch malformed request bodies in mailjet.js
This commit is contained in:
@@ -14,6 +14,12 @@ app.post("/sendemail", (rreq,rres) => {
|
|||||||
} else {
|
} else {
|
||||||
if (dbRes["content"][rreq.get("Authorization").split("_")[0]] === rreq.get("Authorization").split("_")[1]) {
|
if (dbRes["content"][rreq.get("Authorization").split("_")[0]] === rreq.get("Authorization").split("_")[1]) {
|
||||||
|
|
||||||
|
// 2024-05-11: Turbo bodge check to make sure request JSON is valid, probably wont work but whatever
|
||||||
|
if (rreq.body == undefined || rreq.body.recipient == undefined) {
|
||||||
|
console.log(`${rreq.get("cf-connecting-ip")} POST /sendemail returned 400 KEY:${rreq.get("Authorization").split("_")[1]}`)
|
||||||
|
rres.sendStatus(400)
|
||||||
|
} else {
|
||||||
|
|
||||||
let message = {
|
let message = {
|
||||||
"Messages": [
|
"Messages": [
|
||||||
{
|
{
|
||||||
@@ -23,13 +29,12 @@ app.post("/sendemail", (rreq,rres) => {
|
|||||||
},
|
},
|
||||||
"To": [
|
"To": [
|
||||||
{
|
{
|
||||||
"Email": rreq.body.recipient.emailAddr,
|
"Email": rreq.body.recipient,
|
||||||
"Name": rreq.body.recipient.emailName,
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"Subject": rreq.body.message.subject,
|
"Subject": rreq.body.subject || "Request did not include a subject.",
|
||||||
"TextPart": rreq.body.message.content,
|
"TextPart": rreq.body.message || "Request did not include a message.",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -43,13 +48,16 @@ app.post("/sendemail", (rreq,rres) => {
|
|||||||
body: JSON.stringify(message)
|
body: JSON.stringify(message)
|
||||||
}).then(fetchRes => {
|
}).then(fetchRes => {
|
||||||
if (fetchRes.status == 200) {
|
if (fetchRes.status == 200) {
|
||||||
console.log(`${rreq.get("cf-connecting-ip")} POST /sendemail returned 200 KEY:${rreq.get("Authorization")}`)
|
console.log(`${rreq.get("cf-connecting-ip")} POST /sendemail returned 200 KEY:${rreq.get("Authorization").split("_")[1]}`)
|
||||||
rres.sendStatus(200)
|
rres.sendStatus(200)
|
||||||
} else {
|
} else {
|
||||||
console.log(`Mailjet Fetch returned result other than OK: ${fetchRes.status} ${fetchRes.statusText}`)
|
console.log(`Mailjet Fetch returned result other than OK: ${fetchRes.status} ${fetchRes.statusText}`)
|
||||||
rres.sendStatus(500)
|
rres.sendStatus(500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log(`${rreq.get("cf-connecting-ip")} POST /sendemail returned 401`) // log ip of unauthorized requests
|
console.log(`${rreq.get("cf-connecting-ip")} POST /sendemail returned 401`) // log ip of unauthorized requests
|
||||||
|
|||||||
Reference in New Issue
Block a user