/** * Yjs WebSocket sync server for rNotes. * * Uses y-websocket's setupWSConnection for full compatibility * with the y-websocket client WebsocketProvider. */ import http from "http"; import { WebSocketServer } from "ws"; // @ts-ignore — y-websocket/bin/utils has no types import { setupWSConnection } from "y-websocket/bin/utils"; const PORT = parseInt(process.env.SYNC_SERVER_PORT || "4444", 10); const server = http.createServer((req, res) => { if (req.url === "/health") { res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ status: "ok" })); return; } res.writeHead(200); res.end("rNotes sync server"); }); const wss = new WebSocketServer({ server }); wss.on("connection", (ws, req) => { setupWSConnection(ws, req); }); server.listen(PORT, () => { console.log(`rNotes sync server listening on port ${PORT}`); console.log(`WebSocket endpoint: ws://0.0.0.0:${PORT}`); });