From 0a031bd9a8a0ee493747b4dc939c7bea0273c353 Mon Sep 17 00:00:00 2001 From: adriano Date: Thu, 29 Aug 2024 18:09:00 -0300 Subject: [PATCH] fix issues for websocket merge --- backend/src/libs/socket.ts | 12 ++++++------ frontend/server.js | 2 +- frontend/src/components/TicketsManager/index.js | 12 ++++++------ frontend/src/services/api.js | 2 +- frontend/src/services/socket.js | 15 ++++++++------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/backend/src/libs/socket.ts b/backend/src/libs/socket.ts index 8412760..291ceaa 100644 --- a/backend/src/libs/socket.ts +++ b/backend/src/libs/socket.ts @@ -59,14 +59,14 @@ export const initIO = (httpServer: Server): SocketIO => { io = new SocketIO(httpServer, { cors: { - origin: "*", - allowedHeaders: ["my-custom-header"], - credentials: true + origin: process.env.FRONTEND_URL, + //allowedHeaders: ["my-custom-header"], + //credentials: true }, maxHttpBufferSize: 1e8, - pingInterval: 25000, - pingTimeout: 60000, - adapter: createAdapter(pubClient, subClient) + // pingInterval: 25000, + // pingTimeout: 60000, + // adapter: createAdapter(pubClient, subClient) }); diff --git a/frontend/server.js b/frontend/server.js index ff983c1..a05ba32 100644 --- a/frontend/server.js +++ b/frontend/server.js @@ -6,4 +6,4 @@ app.use(express.static(path.join(__dirname, "build"))); app.get("/*", function (req, res) { res.sendFile(path.join(__dirname, "build", "index.html")); }); -app.listen(3331); +app.listen(3333); diff --git a/frontend/src/components/TicketsManager/index.js b/frontend/src/components/TicketsManager/index.js index 18bd1c8..4699948 100644 --- a/frontend/src/components/TicketsManager/index.js +++ b/frontend/src/components/TicketsManager/index.js @@ -152,7 +152,7 @@ const TicketsManager = () => { const [openCount, setOpenCount] = useState(0) const [pendingCount, setPendingCount] = useState(0) - const userQueueIds = user.queues.map((q) => q.id) + const userQueueIds = user?.queues?.map((q) => q?.id) const [selectedQueueIds, setSelectedQueueIds] = useState(userQueueIds || []) const [showContentSearch, setShowContentSearch] = useState(false) @@ -177,9 +177,9 @@ const TicketsManager = () => { }, [setting]) useEffect(() => { - if (user.profile.toUpperCase() === "ADMIN" || - user.profile.toUpperCase() === "SUPERVISOR" || - user.profile.toUpperCase() === "MASTER") { + if (user?.profile?.toUpperCase() === "ADMIN" || + user?.profile?.toUpperCase() === "SUPERVISOR" || + user?.profile?.toUpperCase() === "MASTER") { setShowAllTickets(true) } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -202,11 +202,11 @@ const TicketsManager = () => { if (tickets.length > 0) { const now = new Date() const differenceTime = tickets?.map(ticket => { - const createdAt = new Date(ticket.createdAt) + const createdAt = new Date(ticket?.createdAt) const difference = now - createdAt return difference }) - const sumDifferences = differenceTime.reduce((total, difference) => total + difference, 0) + const sumDifferences = differenceTime?.reduce((total, difference) => total + difference, 0) const averageTimeMilliseconds = sumDifferences / tickets?.length let hours = Math.floor(averageTimeMilliseconds / 3600000) const minutes = Math.floor((averageTimeMilliseconds % 3600000) / 60000) diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index 116eac5..209fc12 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -1,7 +1,7 @@ import axios from "axios"; const api = axios.create({ - baseURL: process.env.REACT_APP_BACKEND_URL + "/api", + baseURL: process.env.REACT_APP_BACKEND_URL, withCredentials: true, }); diff --git a/frontend/src/services/socket.js b/frontend/src/services/socket.js index e0b4950..b54fe15 100644 --- a/frontend/src/services/socket.js +++ b/frontend/src/services/socket.js @@ -3,11 +3,12 @@ import { io } from 'socket.io-client'; // "undefined" means the URL will be computed from the `window.location` object const URL = process.env.REACT_APP_BACKEND_URL -export const socket = io(URL, { - path: "/api-ws/socketio", - withCredentials: true, - extraHeaders: { - "my-custom-header": "abcd" - }, +export const socket = io(URL, +//{ +// withCredentials: true, +// extraHeaders: { +// "my-custom-header": "abcd" +// }, // transports: ['websocket', 'polling'] -}); \ No newline at end of file +//} +); \ No newline at end of file