Last active
December 19, 2020 14:24
-
-
Save HyunsDev/41d4d1977d01c65d524fe56a1c4c79c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/api/write', function (req, res, next) { | |
let d_line = sanitizeHtml(req.body.line); | |
let d_date = moment().format('YY.MM.DD h시 mm분'); | |
let d_author = req.headers['x-forwarded-for'] || req.connection.remoteAddress; | |
if (d_line && d_date && d_author) { | |
if (d_line.len > 300) {res.send({status: "err", reason: "ERR_LINE_SO_LONG"}); | |
} else if (d_line.len == 0) {res.send({status: "err", reason: "ERR_LINE_IS_EMPTY"}); | |
} else { | |
var connection = mysql.createConnection(dbconfig.con); | |
connection.connect(); | |
connection.query("INSERT INTO dayline.lines (dline, created, author) VALUE (?, ?, ?);", [d_line, d_date, d_author], function (error, results, fields) { | |
if (error) { | |
console.log(error); | |
res.send({ | |
status: "err", | |
reason: "ERR_UNKNOWN" | |
}) | |
} else { | |
res.send({ | |
status: "OK", | |
data: { | |
line: d_line, | |
date: d_date | |
} | |
}) | |
} | |
} | |
); | |
connection.end(); | |
} | |
} else { | |
res.send({status: "err", reason: "ERR_CHECK_REQUEST"}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment