File tree 2 files changed +30
-38
lines changed
2 files changed +30
-38
lines changed Original file line number Diff line number Diff line change 1
1
// src/routes/index.ts
2
2
import { FastifyInstance } from 'fastify' ;
3
+ import sensible from '@fastify/sensible' ;
4
+ import { helloHandler } from '../handlers/handlers' ;
3
5
import userRoutes from './api/user.route' ;
4
6
import errorHandler from '../plugins/errorHandler' ;
5
7
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
7
36
await fastify . register ( async ( fastify ) => {
8
- // Register error handler first within the same scope as routes
9
37
await fastify . register ( errorHandler ) ;
10
-
11
- // Register routes in same scope as error handler
12
38
await fastify . register ( userRoutes ) ;
13
- // Add more API route modules here
14
39
} ) ;
15
40
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments