1
0
mirror of synced 2026-01-04 00:06:20 -05:00
Files
docs/middleware/events.js
Peter Bengtsson fab5bef972 Avoid an infinite FailBot.report() loop (#22837)
* Avoid an infinite FailBot.report() loop

Part of #1221

* Update middleware/events.js

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
2021-11-16 01:05:03 +00:00

30 lines
715 B
JavaScript

import express from 'express'
import { omit } from 'lodash-es'
import Ajv from 'ajv'
import addFormats from 'ajv-formats'
import { eventSchema, hydroNames } from '../lib/schema-event.js'
const OMIT_FIELDS = ['type']
const ajv = new Ajv()
addFormats(ajv)
const router = express.Router()
router.post('/', async function postEvents(req, res, next) {
const isDev = process.env.NODE_ENV === 'development'
const fields = omit(req.body, '_csrf')
if (!ajv.validate(eventSchema, fields)) {
return res.status(400).json(isDev ? ajv.errorsText() : {})
}
res.json({})
if (req.hydro.maySend()) {
await req.hydro.publish(hydroNames[fields.type], omit(fields, OMIT_FIELDS))
}
})
export default router