1 ---
2 sidebar_label: "route-file-naming"
3 ---
4
5 export const metadata = {
6 title: `route-file-naming - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule requires API route handlers to be exported from a `route.ts` or `route.js` file under `src/api`.
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 files in your project's `src/api` directory. It reports HTTP method handlers exported from a file that isn't named `route.ts` or `route.js`, and `route` files that export no HTTP method handler.
20
21 The following code is reported by the rule:
22
23 ```ts title="src/api/store/products/handlers.ts"
24 export const GET = async (req, res) => {
25 res.json({})
26 }
27 ```
28
29 Instead, export the handler from a `route` file:
30
31 ```ts title="src/api/store/products/route.ts"
32 export const GET = async (req, res) => {
33 res.json({})
34 }
35 ```
36
37 ## Why it's Important
38
39 Medusa only registers HTTP method handlers exported from `route.ts` or `route.js` files. Handlers placed in other files are never reached, so the route won't work as expected.
40
41 Learn more in the [API Routes documentation](!docs!/learn/fundamentals/api-routes).
42
43 ## Fixable
44
45 This rule isn't auto-fixable.