feat: Added websocket with lib socket.io

This commit is contained in:
Davidson Gomes
2023-08-02 13:08:30 -03:00
parent ed5e66e430
commit 79864e97d6
22 changed files with 72 additions and 19 deletions

25
src/libs/db.connect.ts Normal file
View File

@@ -0,0 +1,25 @@
import mongoose from 'mongoose';
import { configService, Database } from '../config/env.config';
import { Logger } from '../config/logger.config';
const logger = new Logger('MongoDB');
const db = configService.get<Database>('DATABASE');
export const dbserver = (() => {
if (db.ENABLED) {
logger.verbose('connecting');
const dbs = mongoose.createConnection(db.CONNECTION.URI, {
dbName: db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api',
});
logger.verbose('connected in ' + db.CONNECTION.URI);
logger.info('ON - dbName: ' + dbs['$dbName']);
process.on('beforeExit', () => {
logger.verbose('instance destroyed');
dbserver.destroy(true, (error) => logger.error(error));
});
return dbs;
}
})();