Skip to content

Commit 469b1e7

Browse files
author
Matija Petrunic
committed
Update starter to use grouped routes
1 parent 39064e0 commit 469b1e7

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/controllers/sample.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ interface GetQuery {
77
}
88

99
export const get: ApiController<GetQuery> = {
10-
url: "/samples",
1110
handler: async function (request, reply) {
1211
logger.info("Fetching samples", { requestId: request.id });
1312
const sampleRepository = this.db.getCustomRepository(SampleRepository);
@@ -17,6 +16,7 @@ export const get: ApiController<GetQuery> = {
1716
reply.send(await sampleRepository.find());
1817
}
1918
},
19+
2020
opts: {
2121
schema: {
2222
querystring: {

src/routes/index.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { FastifyInstance } from "fastify";
22

3-
import * as sampleController from "../controllers/sample";
3+
import { sampleRoutes } from "./sample";
44

55
export function registerRoutes(server: FastifyInstance): void {
6-
server.get(
7-
sampleController.get.url,
8-
sampleController.get.opts,
9-
sampleController.get.handler
10-
);
6+
server.register(sampleRoutes, { prefix: "/samples" });
117
}

src/routes/sample.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { FastifyInstance } from "fastify";
2+
3+
import * as SampleController from "../controllers/sample";
4+
5+
// /samples prefix
6+
export async function sampleRoutes(server: FastifyInstance): Promise<void> {
7+
server.get("/", SampleController.get.opts, SampleController.get.handler);
8+
}

src/services/fastify-types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export interface ApiController<
2121
Body = DefaultBody,
2222
Headers = DefaultHeaders
2323
> {
24-
url: string;
2524
opts: RouteShorthandOptions;
2625
handler: RouteHandlerMethod<
2726
RawServerDefault,

0 commit comments

Comments
 (0)