Skip to content

Commit

Permalink
Refactor root and index route files into one file.
Browse files Browse the repository at this point in the history
  • Loading branch information
d1str0 committed Nov 28, 2024
1 parent fea8575 commit 66f19f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
35 changes: 30 additions & 5 deletions api/src/routes/index.ts
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
});
}
33 changes: 0 additions & 33 deletions api/src/routes/root.ts

This file was deleted.

0 comments on commit 66f19f8

Please sign in to comment.