redThread / server /src /middleware /safetyGuard.js
3v324v23's picture
Initial commit of RedThread project
0dd2082
raw
history blame contribute delete
413 Bytes
const safetyService = require('../services/safety.service');
const AppError = require('../utils/AppError');
const safetyGuard = (req, res, next) => {
const input = req.body.query || req.query.q;
if (!input) return next();
const result = safetyService.validate(input);
if (!result.safe) {
return next(new AppError(result.reason, 403));
}
next();
};
module.exports = safetyGuard;