11// Load environment and Firebase configuration first
2- import "dotenv/config" ;
2+ import dotenv from "dotenv" ;
3+ dotenv . config ( ) ;
34import "./firebase" ;
45import "reflect-metadata" ;
56
67import {
78 createExpressServer ,
89 useContainer as routingUseContainer ,
10+ ForbiddenError ,
11+ HttpError ,
12+ UnauthorizedError ,
913} from "routing-controllers" ;
1014import { getManager , useContainer } from "typeorm" ;
1115import { Container } from "typeorm-typedi-extensions" ;
1216import { Express , Request , Response } from "express" ;
1317import * as swaggerUi from "swagger-ui-express" ;
14- import swaggerDocument from "../swagger.json" ;
18+ import * as path from "path" ;
19+ import { firebaseAdmin as admin } from "./firebase" ;
1520
1621import { controllers } from './api/controllers' ;
1722import { middlewares } from './api/middlewares' ;
@@ -22,48 +27,6 @@ import { ReportService } from './services/ReportService';
2227import { reportToString } from './utils/Requests' ;
2328import { startTransactionConfirmationCron } from './cron/transactionCron' ;
2429
25- dotenv . config ( ) ;
26-
27- const port = process . env . PORT ?? 3000 ;
28- const app : Express = createExpressServer ( {
29- cors : true ,
30- routePrefix : "/api/" ,
31- controllers : controllers ,
32- middlewares : middlewares ,
33- defaults : {
34- paramOptions : {
35- required : true , // Make all params required by default
36- } ,
37- } ,
38- validation : true ,
39- development : process . env . NODE_ENV !== "production" ,
40- defaultErrorHandler : false ,
41- currentUserChecker : FirebaseCurrentUserChecker ,
42- } ) ;
43-
44- /**
45- * Setup Swagger docs
46- */
47- app . use ( "/api-docs" , swaggerUi . serve , swaggerUi . setup ( swaggerDocument ) ) ;
48- console . log (
49- `Swagger documentation available at http://localhost:${ port } /api-docs` ,
50- ) ;
51-
52- /**
53- * Health check endpoint
54- */
55- app . get ( "/health" , async ( _req : Request , res : Response ) => {
56- const manager = getManager ( ) ;
57- try {
58- await manager . query ( "SELECT 1" ) ;
59- res . status ( 200 ) . json ( { status : "healthy" , database : "Connected" } ) ;
60- } catch ( error ) {
61- res
62- . status ( 500 )
63- . json ( { status : "Error" , database : "Not connected" , error : error } ) ;
64- }
65- } ) ;
66-
6730// Setup dependency injection containers
6831routingUseContainer ( Container ) ;
6932useContainer ( Container ) ;
@@ -175,6 +138,21 @@ async function main() {
175138 `Swagger documentation available at http://localhost:${ port } /api-docs` ,
176139 ) ;
177140
141+ /**
142+ * Health check endpoint
143+ */
144+ app . get ( "/health" , async ( _req : Request , res : Response ) => {
145+ const manager = getManager ( ) ;
146+ try {
147+ await manager . query ( "SELECT 1" ) ;
148+ res . status ( 200 ) . json ( { status : "healthy" , database : "Connected" } ) ;
149+ } catch ( error ) {
150+ res
151+ . status ( 500 )
152+ . json ( { status : "Error" , database : "Not connected" , error : error } ) ;
153+ }
154+ } ) ;
155+
178156 const entityManager = getManager ( ) ;
179157 const reportService = new ReportService ( entityManager ) ;
180158 const reportController = new ReportController ( reportService ) ;
0 commit comments