From ed20671f5ebeb0dbf4bb2d1f03d86ee407125da9 Mon Sep 17 00:00:00 2001 From: Francis Breit Date: Wed, 20 Sep 2023 01:03:54 -0300 Subject: [PATCH] Update main.ts --- src/main.ts | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/main.ts b/src/main.ts index e239f83a..75dd95b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,11 @@ import 'express-async-errors'; -import axios from 'axios'; import compression from 'compression'; import cors from 'cors'; import express, { json, NextFunction, Request, Response, urlencoded } from 'express'; import { join } from 'path'; -import { Auth, configService, Cors, HttpServer, Rabbitmq, Webhook } from './config/env.config'; +import { configService, Cors, HttpServer, Rabbitmq } from './config/env.config'; import { onUnexpectedError } from './config/error.config'; import { Logger } from './config/logger.config'; import { ROOT_DIR } from './config/path.config'; @@ -48,45 +47,11 @@ function bootstrap() { app.set('views', join(ROOT_DIR, 'views')); app.use(express.static(join(ROOT_DIR, 'public'))); - app.use('/store', express.static(join(ROOT_DIR, 'store'))); - app.use('/', router); app.use( (err: Error, req: Request, res: Response, next: NextFunction) => { if (err) { - const webhook = configService.get('WEBHOOK'); - - if (webhook.EVENTS.ERRORS_WEBHOOK && webhook.EVENTS.ERRORS_WEBHOOK != '' && webhook.EVENTS.ERRORS) { - const tzoffset = new Date().getTimezoneOffset() * 60000; //offset in milliseconds - const localISOTime = new Date(Date.now() - tzoffset).toISOString(); - const now = localISOTime; - const globalApiKey = configService.get('AUTHENTICATION').API_KEY.KEY; - const serverUrl = configService.get('SERVER').URL; - - const errorData = { - event: 'error', - data: { - error: err['error'] || 'Internal Server Error', - message: err['message'] || 'Internal Server Error', - status: err['status'] || 500, - response: { - message: err['message'] || 'Internal Server Error', - }, - }, - date_time: now, - api_key: globalApiKey, - server_url: serverUrl, - }; - - logger.error(errorData); - - const baseURL = webhook.EVENTS.ERRORS_WEBHOOK; - const httpService = axios.create({ baseURL }); - - httpService.post('', errorData); - } - return res.status(err['status'] || 500).json({ status: err['status'] || 500, error: err['error'] || 'Internal Server Error', @@ -124,7 +89,7 @@ function bootstrap() { initIO(server); - if (configService.get('RABBITMQ')?.ENABLED) initAMQP(); + if (configService.get('RABBITMQ').ENABLED) initAMQP(); onUnexpectedError(); }