diff --git a/src/server.js b/src/server.js index c6c3f6d..256aa36 100644 --- a/src/server.js +++ b/src/server.js @@ -22,6 +22,18 @@ const app = express(); const server = new createServer(app); const io = new Server(server); +app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { + console.log("⚠️ Certificate error:", url); + + // Allow for ngrok only + if (url.includes("ngrok")) { + event.preventDefault(); + callback(true); // approve the certificate + } else { + callback(false); // reject others + } +}); + app.set("view engine", "ejs"); const PORT = process.env.PORT || 8000; @@ -64,25 +76,25 @@ app.get("/client/forgot-password", (req, res) => { // Client Dashboard Routes with new file names app.get('/client/dashboard', async (req, res) => { - try { - // const dashboardData = await dashboardService.getClientDashboard(req.user.id); - // res.render('client/dashboard-dashboard', dashboardData); - res.render('client/dashboard-dashboard'); - } catch (error) { - console.error('Dashboard error:', error); - res.status(500).render('client/dashboard-dashboard', { error: 'Failed to load dashboard' }); - } + try { + // const dashboardData = await dashboardService.getClientDashboard(req.user.id); + // res.render('client/dashboard-dashboard', dashboardData); + res.render('client/dashboard-dashboard'); + } catch (error) { + console.error('Dashboard error:', error); + res.status(500).render('client/dashboard-dashboard', { error: 'Failed to load dashboard' }); + } }); app.get('/client/virtual-assistants', async (req, res) => { - try { - // const vaData = await virtualAssistantService.getClientVAs(req.user.id); - res.render('client/dashboard-virtual-assistants'); - // res.render('client/dashboard-virtual-assistants', vaData); - } catch (error) { - console.error('Virtual assistants error:', error); - res.status(500).render('client/dashboard-virtual-assistants', { error: 'Failed to load virtual assistants' }); - } + try { + // const vaData = await virtualAssistantService.getClientVAs(req.user.id); + res.render('client/dashboard-virtual-assistants'); + // res.render('client/dashboard-virtual-assistants', vaData); + } catch (error) { + console.error('Virtual assistants error:', error); + res.status(500).render('client/dashboard-virtual-assistants', { error: 'Failed to load virtual assistants' }); + } }); // app.get('/client/timesheets', async (req, res) => { @@ -115,9 +127,14 @@ app.get('/client/virtual-assistants', async (req, res) => { // } // }); -app.get("/live/:projectId/:vaId", (req, res) => { - const { projectId } = req.params; - res.render("va_live_tracker", { title: "VA Live Tracker", projectId }) +app.get("/live/:projectId/:clientId", (req, res) => { + const { projectId, clientId } = req.params; + + if(!projectId || !clientId){ + return res.status(400).send({"message": "Page not found"}); + } + + res.render("va_live_tracker", { title: "VA Live Tracker", projectId, clientId }) }) // Handling Socket @@ -145,7 +162,7 @@ io.use(async (socket, next) => { return next(new Error("Invalid token payload")); } - /* ---------------------- 1⃣ Check if VA ---------------------- */ + /* ---------------------- 1⃣ Check if VA ---------------------- */ let vaUser = null; let clientData = null; @@ -163,7 +180,7 @@ io.use(async (socket, next) => { socket.data.role = "va"; socket.data.vaId = vaUser._id.toString(); socket.data.vaEmail = decoded.email; - + const a = vaProjClientId.toString(); const b = clientData.clientId._id.toString(); const c = JSON.stringify(clientData); @@ -176,7 +193,7 @@ io.use(async (socket, next) => { return next(); } - /* ---------------------- 2⃣ Check if Client ---------------------- */ + /* ---------------------- 2⃣ Check if Client ---------------------- */ // const clientUser = await ClientModel.findOne({ "userDetails.email": decoded.email }); // if (clientUser) { @@ -342,11 +359,6 @@ app.get("/client/forgot-password", (req, res) => { res.render("forgot_password") }) -app.get("/live/:projectId", (req, res) => { - const { projectId } = req.params; - res.render("va_live_tracker", { title: "VA Live Tracker", projectId }) -}) - // Handling Socket import jwt from "jsonwebtoken"; diff --git a/views/va_live_tracker.ejs b/views/va_live_tracker.ejs index d05223c..cb9006a 100644 --- a/views/va_live_tracker.ejs +++ b/views/va_live_tracker.ejs @@ -89,10 +89,13 @@