You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tellme-bot/packages/server/handlers/parser.js

41 lines
998 B

1 year ago
import DOMPurify from 'isomorphic-dompurify'
1 year ago
/**
*
* handle parser
*
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
*
*/
async function parserHandler(request, response) {
// getting allowed parsers from .env as array
const allowedParsers = process.env.APP_API_ALLOWED_PARSERS.split(',')
// getting name from request
const parserName = DOMPurify.sanitize(request.params.parser)
// if parser not found send 404
if (allowedParsers.indexOf(parserName) === -1) {
1 year ago
console.log('Parsers: "' + parserName + '" not found!')
1 year ago
return response
.code(404)
.send()
}
// getting parser and set body to parser
1 year ago
const Parser = await import('./../parsers/' + parserName + '.js')
response.locals = {
parser: new Parser.default(request.body)
}
1 year ago
}
export default parserHandler