-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor root and index route files into one file.
- Loading branch information
Showing
2 changed files
with
30 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,40 @@ | ||
// src/routes/index.ts | ||
import { FastifyInstance } from 'fastify'; | ||
import sensible from '@fastify/sensible'; | ||
import { helloHandler } from '../handlers/handlers'; | ||
import userRoutes from './api/user.route'; | ||
import errorHandler from '../plugins/errorHandler'; | ||
|
||
export default async function apiRoutes(fastify: FastifyInstance) { | ||
export default async function routes(fastify: FastifyInstance) { | ||
fastify.register(sensible); | ||
|
||
// Root routes | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler: async function () { | ||
fastify.log.info('GET / route hit'); | ||
return { root: true }; | ||
}, | ||
}); | ||
|
||
fastify.route({ | ||
method: 'GET', | ||
url: '/error', | ||
handler: async function () { | ||
throw new Error('Test error'); | ||
}, | ||
}); | ||
|
||
fastify.route({ | ||
method: 'GET', | ||
url: '/hello', | ||
handler: helloHandler, | ||
}); | ||
|
||
// API routes with error handler | ||
await fastify.register(async (fastify) => { | ||
// Register error handler first within the same scope as routes | ||
await fastify.register(errorHandler); | ||
|
||
// Register routes in same scope as error handler | ||
await fastify.register(userRoutes); | ||
// Add more API route modules here | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.