Skip to content

Commit 66f19f8

Browse files
committed
Refactor root and index route files into one file.
1 parent fea8575 commit 66f19f8

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed

api/src/routes/index.ts

+30-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
// src/routes/index.ts
22
import { FastifyInstance } from 'fastify';
3+
import sensible from '@fastify/sensible';
4+
import { helloHandler } from '../handlers/handlers';
35
import userRoutes from './api/user.route';
46
import errorHandler from '../plugins/errorHandler';
57

6-
export default async function apiRoutes(fastify: FastifyInstance) {
8+
export default async function routes(fastify: FastifyInstance) {
9+
fastify.register(sensible);
10+
11+
// Root routes
12+
fastify.route({
13+
method: 'GET',
14+
url: '/',
15+
handler: async function () {
16+
fastify.log.info('GET / route hit');
17+
return { root: true };
18+
},
19+
});
20+
21+
fastify.route({
22+
method: 'GET',
23+
url: '/error',
24+
handler: async function () {
25+
throw new Error('Test error');
26+
},
27+
});
28+
29+
fastify.route({
30+
method: 'GET',
31+
url: '/hello',
32+
handler: helloHandler,
33+
});
34+
35+
// API routes with error handler
736
await fastify.register(async (fastify) => {
8-
// Register error handler first within the same scope as routes
937
await fastify.register(errorHandler);
10-
11-
// Register routes in same scope as error handler
1238
await fastify.register(userRoutes);
13-
// Add more API route modules here
1439
});
1540
}

api/src/routes/root.ts

-33
This file was deleted.

0 commit comments

Comments
 (0)