From 82e2e332cf3d22b0688ad6b364dfcb6f3bb7727d Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Tue, 24 Sep 2024 20:54:14 -0400 Subject: [PATCH] IO-2935-Add-Enhanced-Websocket-Provider - fixes Signed-off-by: Dave Richer --- client/src/contexts/SocketIO/useSocket.js | 2 +- .../dms-payables/dms-payables.container.jsx | 17 +++++++---------- client/src/pages/dms/dms.container.jsx | 2 +- server.js | 16 ++++++++++++---- server/utils/redisHelpers.js | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/client/src/contexts/SocketIO/useSocket.js b/client/src/contexts/SocketIO/useSocket.js index 14adbb144..f75fd3fea 100644 --- a/client/src/contexts/SocketIO/useSocket.js +++ b/client/src/contexts/SocketIO/useSocket.js @@ -8,7 +8,7 @@ const useSocket = (bodyshop) => { useEffect(() => { if (bodyshop && bodyshop.id) { - const endpoint = import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "https://localhost:3000"; + const endpoint = import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : ""; const socketInstance = SocketIO(endpoint, { path: "/wss", // Ensure this matches the Vite proxy and backend path diff --git a/client/src/pages/dms-payables/dms-payables.container.jsx b/client/src/pages/dms-payables/dms-payables.container.jsx index f0c0e6c33..de796ca6b 100644 --- a/client/src/pages/dms-payables/dms-payables.container.jsx +++ b/client/src/pages/dms-payables/dms-payables.container.jsx @@ -23,17 +23,14 @@ const mapDispatchToProps = (dispatch) => ({ export default connect(mapStateToProps, mapDispatchToProps)(DmsContainer); -export const socket = SocketIO( - import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "https://localhost:3000", - { - path: "/ws", - withCredentials: true, - auth: async (callback) => { - const token = auth.currentUser && (await auth.currentUser.getIdToken()); - callback({ token }); - } +export const socket = SocketIO(import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", { + path: "/ws", + withCredentials: true, + auth: async (callback) => { + const token = auth.currentUser && (await auth.currentUser.getIdToken()); + callback({ token }); } -); +}); export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) { const { t } = useTranslation(); diff --git a/client/src/pages/dms/dms.container.jsx b/client/src/pages/dms/dms.container.jsx index 50198cb6e..9cbc3ea50 100644 --- a/client/src/pages/dms/dms.container.jsx +++ b/client/src/pages/dms/dms.container.jsx @@ -34,7 +34,7 @@ const mapDispatchToProps = (dispatch) => ({ export default connect(mapStateToProps, mapDispatchToProps)(DmsContainer); export const socket = SocketIO( - import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "http://localhost:3000", // for dev testing, + import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", // for dev testing, { path: "/ws", withCredentials: true, diff --git a/server.js b/server.js index dbc52b68f..13456129c 100644 --- a/server.js +++ b/server.js @@ -11,6 +11,7 @@ const { createAdapter } = require("@socket.io/redis-adapter"); const logger = require("./server/utils/logger"); const { redisSocketEvents } = require("./server/web-sockets/redisSocketEvents"); const { instrument, RedisStore } = require("@socket.io/admin-ui"); + const { isString, isEmpty } = require("lodash"); const applyRedisHelpers = require("./server/utils/redisHelpers"); @@ -27,6 +28,7 @@ const SOCKETIO_CORS_ORIGIN = [ "https://test.imex.online", "https://www.test.imex.online", "http://localhost:3000", + "https://localhost:3000", "https://imex.online", "https://www.imex.online", "https://romeonline.io", @@ -46,7 +48,9 @@ const SOCKETIO_CORS_ORIGIN = [ "https://old.imex.online", "https://www.old.imex.online", "https://wsadmin.imex.online", - "https://www.wsadmin.imex.online" + "https://www.wsadmin.imex.online", + "http://localhost:3333", + "https://localhost:3333" ]; /** @@ -58,8 +62,13 @@ const applyMiddleware = (app) => { app.use(cookieParser()); app.use(bodyParser.json({ limit: "50mb" })); app.use(bodyParser.urlencoded({ limit: "50mb", extended: true })); - app.use(cors({ credentials: true, exposedHeaders: ["set-cookie"] })); - + app.use( + cors({ + origin: SOCKETIO_CORS_ORIGIN, + credentials: true, + exposedHeaders: ["set-cookie"] + }) + ); // Helper middleware app.use((req, res, next) => { req.logger = logger; @@ -142,7 +151,6 @@ const applySocketIO = async (server, app) => { username: "admin", password: process.env.REDIS_ADMIN_PASS }, - store: new RedisStore(pubClient), mode: process.env.REDIS_ADMIN_MODE || "development" }); } diff --git a/server/utils/redisHelpers.js b/server/utils/redisHelpers.js index ee8acc890..df2c10303 100644 --- a/server/utils/redisHelpers.js +++ b/server/utils/redisHelpers.js @@ -183,7 +183,7 @@ const applyRedisHelpers = (pubClient, app) => { // if (process.env.NODE_ENV === "development") { // demoSessionData(); // } - + // "th1s1sr3d1s" (BCrypt) return api; }; module.exports = applyRedisHelpers;