Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scan): route groups #2664

Merged
merged 13 commits into from
Sep 29, 2024
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/core/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export async function scanServerRoutes(
return files.map((file) => {
let route = file.path
.replace(/\.[A-Za-z]+$/, "")
.replace(/\(([^(/\\]+)\)[/\\]/g, "")
.replace(/\[\.{3}]/g, "**")
.replace(/\[\.{3}(\w+)]/g, "**:$1")
.replace(/\[(\w+)]/g, ":$1");
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/routes/(route-group)/route-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default defineEventHandler((event) => {
return "Hi from inside group";
});
9 changes: 9 additions & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ export function testNitro(
expect(paramsData2).toBe("foo/bar/baz");
});

it("group routes", async () => {
const { status } = await callHandler({ url: "/route-group" });
expect(status).toBe(200);
const { status: apiStatus } = await callHandler({
url: "/route-group",
});
expect(apiStatus).toBe(200);
});

it("Handle 404 not found", async () => {
const res = await callHandler({ url: "/api/not-found" });
expect(res.status).toBe(404);
Expand Down