Skip to content

Commit

Permalink
fix(scanner): allow having http method as part of the route name (#1895)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 8, 2023
1 parent c5cfca1 commit 223c09d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scan.ts
Expand Up @@ -7,7 +7,7 @@ export const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
type FileInfo = { path: string; fullPath: string };

const httpMethodRegex =
/\.(connect|delete|get|head|options|patch|post|put|trace)/;
/\.(connect|delete|get|head|options|patch|post|put|trace)$/;

export async function scanHandlers(nitro: Nitro) {
const middleware = await scanMiddleware(nitro);
Expand Down
1 change: 1 addition & 0 deletions test/fixture/api/methods/foo.get.get.ts
@@ -0,0 +1 @@
export default defineEventHandler(() => "foo.get");
1 change: 1 addition & 0 deletions test/fixture/api/methods/get.ts
@@ -0,0 +1 @@
export default defineEventHandler(() => "get");
9 changes: 9 additions & 0 deletions test/tests.ts
Expand Up @@ -620,4 +620,13 @@ export function testNitro(
}
);
});

describe("scanned files", () => {
it("Allow having extra method in file name", async () => {
expect((await callHandler({ url: "/api/methods/get" })).data).toBe("get");
expect((await callHandler({ url: "/api/methods/foo.get" })).data).toBe(
"foo.get"
);
});
});
}

0 comments on commit 223c09d

Please sign in to comment.