Skip to content

Commit

Permalink
Explicitly no cache on /api/events (github#29549)
Browse files Browse the repository at this point in the history
  • Loading branch information
heiskr authored Aug 2, 2022
1 parent bf1c6a2 commit 11267f2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions middleware/api/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import Ajv from 'ajv'
import addFormats from 'ajv-formats'
import { eventSchema, hydroNames } from '../../lib/schema-event.js'
import catchMiddlewareError from '../catch-middleware-error.js'
import { cacheControlFactory } from '../cache-control.js'

const OMIT_FIELDS = ['type']

const router = express.Router()
const noCacheControl = cacheControlFactory(0)
const ajv = new Ajv()
addFormats(ajv)

const router = express.Router()
const OMIT_FIELDS = ['type']

router.post(
'/',
catchMiddlewareError(async function postEvents(req, res, next) {
catchMiddlewareError(async function postEvents(req, res) {
const isDev = process.env.NODE_ENV === 'development'
const fields = omit(req.body, '_csrf')
noCacheControl(res)

if (!ajv.validate(eventSchema, fields)) {
return res.status(400).json(isDev ? ajv.errorsText() : {})
Expand Down

0 comments on commit 11267f2

Please sign in to comment.