diff --git a/middleware/index.js b/middleware/index.js index 8e37a657ac56..f5d203061a92 100644 --- a/middleware/index.js +++ b/middleware/index.js @@ -15,7 +15,6 @@ import { setDefaultFastlySurrogateKey, setLanguageFastlySurrogateKey, } from './set-fastly-surrogate-key.js' -import reqUtils from './req-utils.js' import handleErrors from './handle-errors.js' import handleInvalidPaths from './handle-invalid-paths.js' import handleNextDataPath from './handle-next-data-path.js' @@ -211,7 +210,6 @@ export default function (app) { app.set('etag', false) // We will manage our own ETags if desired // *** Config and context for redirects *** - app.use(reqUtils) // Must come before events app.use(instrument(detectLanguage, './detect-language')) // Must come before context, breadcrumbs, find-page, handle-errors, homepages app.use(asyncMiddleware(instrument(reloadTree, './reload-tree'))) // Must come before context app.use(asyncMiddleware(instrument(context, './context'))) // Must come before early-access-*, handle-redirects diff --git a/middleware/req-utils.js b/middleware/req-utils.js deleted file mode 100644 index aea4926c4972..000000000000 --- a/middleware/req-utils.js +++ /dev/null @@ -1,6 +0,0 @@ -import Hydro from '../src/events/hydro.js' - -export default function reqUtils(req, res, next) { - req.hydro = new Hydro() - return next() -} diff --git a/src/events/middleware.js b/src/events/middleware.js index f54e25116204..7dceba73d3c1 100644 --- a/src/events/middleware.js +++ b/src/events/middleware.js @@ -5,7 +5,9 @@ import addFormats from 'ajv-formats' import { eventSchema, hydroNames } from './schema.js' import catchMiddlewareError from '../../middleware/catch-middleware-error.js' import { noCacheControl } from '../../middleware/cache-control.js' +import Hydro from './hydro.js' +const hydro = new Hydro() const router = express.Router() const ajv = new Ajv() addFormats(ajv) @@ -23,14 +25,13 @@ router.post( res.json({}) - if (req.hydro.maySend()) { + if (hydro.maySend()) { try { - await req.hydro.publish(hydroNames[req.body.type], omit(req.body, OMIT_FIELDS)) + await hydro.publish(hydroNames[req.body.type], omit(req.body, OMIT_FIELDS)) } catch (err) { console.error('Failed to submit event to Hydro', err) } } }) ) - export default router