1 ---
2 sidebar_label: "middlewares-file-location-and-name"
3 ---
4
5 export const metadata = {
6 title: `middlewares-file-location-and-name - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule requires middlewares to be defined in `src/api/middlewares.ts` with a default export of `defineMiddlewares`.
12
13 ## Severity
14
15 `error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset.
16
17 ## What it Targets
18
19 This rule targets the `src/api/middlewares.ts` file. It reports a middleware file with the wrong name, such as a singular `middleware.ts`, a file in the wrong directory, or a canonical file that doesn't default-export `defineMiddlewares`.
20
21 The following code is reported by the rule, since the file uses the singular name:
22
23 ```ts title="src/api/middleware.ts"
24 import { defineMiddlewares } from "@medusajs/framework/http"
25
26 export default defineMiddlewares({ routes: [] })
27 ```
28
29 Instead, use the plural `middlewares.ts` name at the canonical location:
30
31 ```ts title="src/api/middlewares.ts"
32 import { defineMiddlewares } from "@medusajs/framework/http"
33
34 export default defineMiddlewares({ routes: [] })
35 ```
36
37 ## Why it's Important
38
39 Medusa only loads middlewares from `src/api/middlewares.ts` with a default export of `defineMiddlewares`. A file with another name or location is ignored, so its middlewares never run.
40
41 Learn more in the [Middlewares documentation](!docs!/learn/fundamentals/api-routes/middlewares).
42
43 ## Fixable
44
45 This rule isn't auto-fixable.