www/apps/resources/app/lint/rules/middleware-must-call-next/page.mdx
export const metadata = {
title: middleware-must-call-next - ESLint plugin rules,
}
This rule requires middleware functions registered via defineMiddlewares to reference their next parameter.
warn. This rule is enabled in the recommended preset.
This rule targets the src/api/middlewares.ts file. It reports a middleware function that declares a next parameter but never references it, which stops the middleware chain.
The following code is reported by the rule:
export default defineMiddlewares({
routes: [
{
matcher: "/store/custom",
middlewares: [(req, res, next) => { res.json({}) }],
},
],
})
Instead, call next so the chain continues:
export default defineMiddlewares({
routes: [
{
matcher: "/store/custom",
middlewares: [(req, res, next) => { next() }],
},
],
})
A middleware that doesn't call next (or end the response) leaves the request hanging, so the route handler is never reached. Referencing next keeps the middleware chain moving.
Learn more in the Middlewares documentation.
This rule isn't auto-fixable.
To turn off this rule, set it to off in your ESLint configuration:
import { defineConfig } from "eslint/config"
import medusa from "@medusajs/eslint-plugin"
export default defineConfig([
...medusa.configs.recommended,
{
rules: {
"@medusajs/middleware-must-call-next": "off",
},
},
])
Or disable it for a single line using an inline comment:
// eslint-disable-next-line @medusajs/middleware-must-call-next
middlewares: [(req, res, next) => { res.json({}) }],