@@ -4,9 +4,10 @@ import express, {
44 type Response
55} from 'express' ;
66import cors from 'cors' ;
7- import { ENV_VARS } from '@/app- constants' ;
7+ import { ENV_CONFIG } from '@/constants' ;
88import { requestLogger } from '@/middleware' ;
9- import * as Routes from '@/routes' ;
9+ import { routesList } from '@/routes' ;
10+ import { sendErrorResponse } from '@/utils' ;
1011
1112const app : Express = express ( ) ;
1213
@@ -17,15 +18,22 @@ app.use(cors());
1718app . use ( requestLogger ) ;
1819
1920app . get ( '/' , ( _ : Request , response : Response ) => {
20- response . status ( 200 ) . send ( `ENV: ${ ENV_VARS . env } - Api is up & running!!!` ) ;
21+ response . status ( 200 ) . json ( {
22+ env : ENV_CONFIG . env ,
23+ message : 'Api is up & running!!!'
24+ } ) ;
2125} ) ;
2226
23- app . use ( '/api/auth' , Routes . authRouter ) ;
27+ routesList . forEach ( route => app . use ( route . path , route . router ) ) ;
2428
2529/* 404 Handler - To be written at last */
2630app . get ( '*' , ( req : Request , response : Response ) => {
27- const notFoundMsg = `Not Found - "${ req . originalUrl } "` ;
28- response . status ( 404 ) . send ( notFoundMsg ) ;
31+ const notFoundError = `No route exists for this endpoint: "${ req . originalUrl } "` ;
32+ return sendErrorResponse ( response , {
33+ statusCode : 404 ,
34+ message : '404 - Not Found' ,
35+ error : notFoundError
36+ } ) ;
2937} ) ;
3038
3139export default app ;
0 commit comments