mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
before adding eslint
This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
require("express-async-errors");
|
||||
require("./database");
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
const Youch = require("youch");
|
||||
const cors = require("cors");
|
||||
const multer = require("multer");
|
||||
const Sentry = require("@sentry/node");
|
||||
|
||||
const { initWbot } = require("./libs/wbot");
|
||||
const wbotMessageListener = require("./services/wbotMessageListener");
|
||||
const wbotMonitor = require("./services/wbotMonitor");
|
||||
const Whatsapp = require("./models/Whatsapp");
|
||||
|
||||
const Router = require("./router");
|
||||
|
||||
const app = express();
|
||||
|
||||
const server = app.listen(process.env.PORT, () => {
|
||||
console.log(`Server started on port: ${process.env.PORT}`);
|
||||
});
|
||||
|
||||
Sentry.init({ dsn: process.env.SENTRY_DSN });
|
||||
|
||||
const fileStorage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
cb(null, path.resolve(__dirname, "..", "public"));
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
cb(null, new Date().getTime() + path.extname(file.originalname));
|
||||
},
|
||||
});
|
||||
|
||||
app.use(Sentry.Handlers.requestHandler());
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(multer({ storage: fileStorage }).single("media"));
|
||||
app.use("/public", express.static(path.join(__dirname, "..", "public")));
|
||||
app.use(Router);
|
||||
|
||||
const io = require("./libs/socket").init(server);
|
||||
io.on("connection", socket => {
|
||||
console.log("Client Connected");
|
||||
socket.on("joinChatBox", ticketId => {
|
||||
console.log("A client joined a ticket channel");
|
||||
socket.join(ticketId);
|
||||
});
|
||||
|
||||
socket.on("joinNotification", () => {
|
||||
console.log("A client joined notification channel");
|
||||
socket.join("notification");
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log("Client disconnected");
|
||||
});
|
||||
});
|
||||
|
||||
const startWhatsAppSessions = async () => {
|
||||
const whatsapps = await Whatsapp.findAll();
|
||||
|
||||
if (whatsapps.length > 0) {
|
||||
whatsapps.forEach(whatsapp => {
|
||||
initWbot(whatsapp)
|
||||
.then(() => {
|
||||
wbotMessageListener(whatsapp);
|
||||
wbotMonitor(whatsapp);
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
});
|
||||
}
|
||||
};
|
||||
startWhatsAppSessions();
|
||||
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
app.use(async (err, req, res, next) => {
|
||||
if (process.env.NODE_ENV === "DEVELOPMENT") {
|
||||
const errors = await new Youch(err, req).toJSON();
|
||||
console.log(err);
|
||||
return res.status(500).json(errors);
|
||||
}
|
||||
|
||||
return res.status(500).json({ error: "Internal server error" });
|
||||
});
|
||||
86
backend/src/server.ts
Normal file
86
backend/src/server.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import "express-async-errors";
|
||||
import express from "express";
|
||||
import path from "path";
|
||||
import cors from "cors";
|
||||
import multer from "multer";
|
||||
// import Sentry from "@sentry/node";
|
||||
// require("./database");
|
||||
|
||||
console.log("eae");
|
||||
|
||||
// const { initWbot } = require("./libs/wbot");
|
||||
// const wbotMessageListener = require("./services/wbotMessageListener");
|
||||
// const wbotMonitor = require("./services/wbotMonitor");
|
||||
// const Whatsapp = require("./models/Whatsapp");
|
||||
|
||||
// const Router = require("./router");
|
||||
|
||||
// const app = express();
|
||||
|
||||
// const server = app.listen(process.env.PORT, () => {
|
||||
// console.log(`Server started on port: ${process.env.PORT}`);
|
||||
// });
|
||||
|
||||
// Sentry.init({ dsn: process.env.SENTRY_DSN });
|
||||
|
||||
// const fileStorage = multer.diskStorage({
|
||||
// destination: (req, file, cb) => {
|
||||
// cb(null, path.resolve(__dirname, "..", "public"));
|
||||
// },
|
||||
// filename: (req, file, cb) => {
|
||||
// cb(null, new Date().getTime() + path.extname(file.originalname));
|
||||
// },
|
||||
// });
|
||||
|
||||
// app.use(Sentry.Handlers.requestHandler());
|
||||
// app.use(cors());
|
||||
// app.use(express.json());
|
||||
// app.use(multer({ storage: fileStorage }).single("media"));
|
||||
// app.use("/public", express.static(path.join(__dirname, "..", "public")));
|
||||
// app.use(Router);
|
||||
|
||||
// const io = require("./libs/socket").init(server);
|
||||
// io.on("connection", socket => {
|
||||
// console.log("Client Connected");
|
||||
// socket.on("joinChatBox", ticketId => {
|
||||
// console.log("A client joined a ticket channel");
|
||||
// socket.join(ticketId);
|
||||
// });
|
||||
|
||||
// socket.on("joinNotification", () => {
|
||||
// console.log("A client joined notification channel");
|
||||
// socket.join("notification");
|
||||
// });
|
||||
|
||||
// socket.on("disconnect", () => {
|
||||
// console.log("Client disconnected");
|
||||
// });
|
||||
// });
|
||||
|
||||
// const startWhatsAppSessions = async () => {
|
||||
// const whatsapps = await Whatsapp.findAll();
|
||||
|
||||
// if (whatsapps.length > 0) {
|
||||
// whatsapps.forEach(whatsapp => {
|
||||
// initWbot(whatsapp)
|
||||
// .then(() => {
|
||||
// wbotMessageListener(whatsapp);
|
||||
// wbotMonitor(whatsapp);
|
||||
// })
|
||||
// .catch(err => console.log(err));
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
// startWhatsAppSessions();
|
||||
|
||||
// app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
// app.use(async (err, req, res, next) => {
|
||||
// if (process.env.NODE_ENV === "DEVELOPMENT") {
|
||||
// const errors = await new Youch(err, req).toJSON();
|
||||
// console.log(err);
|
||||
// return res.status(500).json(errors);
|
||||
// }
|
||||
|
||||
// return res.status(500).json({ error: "Internal server error" });
|
||||
// });
|
||||
Reference in New Issue
Block a user