const express = require('express'); const router = express.Router(); const db = require("../dependencies"); router.post("/reset", (req, res) => { db.prepare("BEGIN TRANSACTION; DELETE FROM accounts; DELETE FROM transaction_entries; DELETE FROM transactions COMMIT;") }) var socket function socketConnectionRequest(req, res, next) { const headers = { 'Content-Type': 'text/event-stream', // To tell client, it is event stream 'Connection': 'keep-alive', // To tell client, not to close connection }; res.writeHead(200, headers); res.write('data: Connection Established, We\'ll now start receiving messages from the server.\n') socket = res console.log('New connection established') } const update = new Map() async function mysse(req, res) { console.log('Got /events'); res.set({ 'Cache-Control': 'no-cache', 'Content-Type': 'text/event-stream', 'Connection': 'keep-alive' }); res.flushHeaders(); // Tell the client to retry every 10 seconds if connectivity is lost res.write('retry: 10000\n\n'); update.set(req.sessionId, res) console.log("connected") res.on("close", () => { update.delete(req.sessionId) res.end() }) }; function set_update() { update = true; } module.exports = { router, mysse, update};