mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 18:38:39 -06:00
Update main.ts
This commit is contained in:
parent
f9fda6af75
commit
ed20671f5e
39
src/main.ts
39
src/main.ts
@ -1,12 +1,11 @@
|
|||||||
import 'express-async-errors';
|
import 'express-async-errors';
|
||||||
|
|
||||||
import axios from 'axios';
|
|
||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
|
||||||
import { join } from 'path';
|
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 { onUnexpectedError } from './config/error.config';
|
||||||
import { Logger } from './config/logger.config';
|
import { Logger } from './config/logger.config';
|
||||||
import { ROOT_DIR } from './config/path.config';
|
import { ROOT_DIR } from './config/path.config';
|
||||||
@ -48,45 +47,11 @@ function bootstrap() {
|
|||||||
app.set('views', join(ROOT_DIR, 'views'));
|
app.set('views', join(ROOT_DIR, 'views'));
|
||||||
app.use(express.static(join(ROOT_DIR, 'public')));
|
app.use(express.static(join(ROOT_DIR, 'public')));
|
||||||
|
|
||||||
app.use('/store', express.static(join(ROOT_DIR, 'store')));
|
|
||||||
|
|
||||||
app.use('/', router);
|
app.use('/', router);
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
const webhook = configService.get<Webhook>('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<Auth>('AUTHENTICATION').API_KEY.KEY;
|
|
||||||
const serverUrl = configService.get<HttpServer>('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({
|
return res.status(err['status'] || 500).json({
|
||||||
status: err['status'] || 500,
|
status: err['status'] || 500,
|
||||||
error: err['error'] || 'Internal Server Error',
|
error: err['error'] || 'Internal Server Error',
|
||||||
@ -124,7 +89,7 @@ function bootstrap() {
|
|||||||
|
|
||||||
initIO(server);
|
initIO(server);
|
||||||
|
|
||||||
if (configService.get<Rabbitmq>('RABBITMQ')?.ENABLED) initAMQP();
|
if (configService.get<Rabbitmq>('RABBITMQ').ENABLED) initAMQP();
|
||||||
|
|
||||||
onUnexpectedError();
|
onUnexpectedError();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user