ba8bfc3f46
User-facing - New post-login home (/home): chat rail + Share/Connect (embedded) + Meeting; login lives here when logged out - Landing: "Log in with BizGaze" + no-login screen share - Console replaced by a role-scoped Dashboard (/dashboard): admins see all team sessions, others see only their own; stats + CSV/PDF export - Recordings saved as MP4 (H.264/AAC) with WebM fallback; old .webm still downloadable - Fix: duplicate "Sign in" on the login card Auth / integration - BizGaze as identity provider: /api/login validates against BIZGAZE_LOGIN_URL (env-gated) and provisions a local user - Phase 2 start: /api/v1 alias for all /api routes; Authorization: Bearer accepted across HTTP + WS; login returns a token (for native desktop/mobile clients) Backend refactor (Phase 1, behavior-preserving) - Split server.js into config/lib/session/presence/routes/static/signaling + repos (data-access) + bizgaze (service) - All SQL behind repos.js, tenant-scoped (tenantId == team_id for now) - e2e updated to current flow (21/21 pass before and after) Docs: ARCHITECTURE.md (target architecture + phased plan), CLAUDE.md repo layout, .env.example BIZGAZE_LOGIN_URL Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.7 KiB
JavaScript
65 lines
2.7 KiB
JavaScript
// BizGaze Connect — backend entry point.
|
|
// Thin wiring layer: HTTP request dispatch + WebSocket attach + listeners.
|
|
// All logic lives in focused modules:
|
|
// repos.js data-access (all SQL)
|
|
// bizgaze.js BizGaze identity provider
|
|
// lib.js HTTP helpers (json/readBody/parseCookies/now)
|
|
// session.js currentUser / audit
|
|
// presence.js shared in-memory live state (agents/sessions/shares)
|
|
// routes.js HTTP JSON API (/api/*, /sso)
|
|
// static.js static files + authenticated downloads (GET fallback)
|
|
// signaling.js WebSocket signaling (consent + SDP/ICE relay)
|
|
const http = require('http');
|
|
const https = require('https');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { WebSocketServer } = require('ws');
|
|
const { PORT, HTTPS_PORT } = require('./config');
|
|
const { json } = require('./lib');
|
|
const routes = require('./routes');
|
|
const { handleGet } = require('./static');
|
|
const { onConnection } = require('./signaling');
|
|
|
|
// ---------- HTTP request dispatch ----------
|
|
const server = http.createServer((req, res) => {
|
|
const key = `${req.method} ${req.url.split('?')[0]}`;
|
|
if (routes[key]) return routes[key](req, res);
|
|
if (req.method === 'GET') return handleGet(req, res); // downloads + static
|
|
json(res, 404, { error: 'not found' });
|
|
});
|
|
|
|
// ---------- WebSocket signaling ----------
|
|
const wss = new WebSocketServer({ server, path: '/ws' });
|
|
wss.on('connection', onConnection);
|
|
|
|
server.listen(PORT, () => {
|
|
console.log(`HTTP on http://localhost:${PORT}`);
|
|
});
|
|
|
|
// HTTPS — required so other devices can share their screen (browsers block
|
|
// screen capture on non-secure origins). Uses cert.pem/key.pem if present.
|
|
let httpsServer = null;
|
|
try {
|
|
const certPath = path.join(__dirname, 'cert.pem');
|
|
const keyPath = path.join(__dirname, 'key.pem');
|
|
if (fs.existsSync(certPath) && fs.existsSync(keyPath)) {
|
|
httpsServer = https.createServer(
|
|
{ cert: fs.readFileSync(certPath), key: fs.readFileSync(keyPath) },
|
|
(req, res) => server.emit('request', req, res)
|
|
);
|
|
const wssSecure = new WebSocketServer({ server: httpsServer, path: '/ws' });
|
|
wssSecure.on('connection', onConnection);
|
|
httpsServer.listen(HTTPS_PORT, () => {
|
|
console.log(`HTTPS on https://localhost:${HTTPS_PORT} (use this address from other devices)`);
|
|
console.log(` End user shares screen: https://<this-pc-ip>:${HTTPS_PORT}/share`);
|
|
console.log(` Technician connects: https://<this-pc-ip>:${HTTPS_PORT}/connect`);
|
|
});
|
|
} else {
|
|
console.log('(No cert.pem/key.pem found — HTTPS disabled. Other devices can view but not share their screen.)');
|
|
}
|
|
} catch (e) {
|
|
console.log('HTTPS failed to start:', e.message);
|
|
}
|
|
|
|
module.exports = { server };
|