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ourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/@vizstack/vz-logger@0.1.9/dist/server.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n'use strict';\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar express = _interopDefault(require('express'));\nvar http = _interopDefault(require('http'));\nvar path = _interopDefault(require('path'));\nvar socketio = _interopDefault(require('socket.io'));\nvar dotenv = _interopDefault(require('dotenv'));\n\n/**\n * This file defines the main server. It can be configured in the future to use HTTPS:\n * https://stackoverflow.com/questions/11744975/enabling-https-on-express-js\n */\n// Load environment configuration variable into `process.env`.\ndotenv.config();\n// Create an Express.js server to handle requests **from** the client using REST, and push realtime\n// updates **to** the client using SocketIO.\nconst app = express();\nconst serverHttp = http.createServer(app);\nlet io = socketio(serverHttp);\n// =================================================================================================\n// Frontend request handlers.\n// Set directory to serve files from (e.g. React client).\napp.use(express.static(path.join(__dirname, '../build')));\napp.get('/', (req, res) => {\n    res.sendFile(path.join(__dirname, '../build', 'index.html'));\n});\n/**\n * GET /hello\n * Sends an acknowledgement string, so that a client can check whether the server is up and running.\n */\napp.get('/hello', function (req, resp) {\n    resp.send(`Server is up and running!`);\n});\n// =================================================================================================\n// Socket handlers.\nconst program = io.of('/program');\nconst frontend = io.of('/frontend');\n/**\n * NAMESPACE /program\n * Channel through which backend loggers communicate log records to this server.\n */\nprogram.on('connect', (socket) => {\n    console.debug(`Program connected: ${socket.id}`);\n    socket.on('disconnect', () => {\n        console.debug(`Program disconnected: ${socket.id}`);\n    });\n    socket.on('ProgramToServer', (msg) => {\n        console.debug('Received message:', msg);\n        frontend.emit('ServerToFrontend', msg);\n        // TODO: append to file on disk (must be thread-safe)\n    });\n    // Some clients will experience issues if they attempt to disconnect before \n    // the server has finished processing its messages. Those clients, when \n    // seeking to disconnect, will instead send \"ProgramRequestDisconnect\", \n    // to which the server will reply and tell the client that all messages have\n    // been consumed and it may safely disconnect.\n    socket.on('ProgramRequestDisconnect', () => {\n        socket.emit('ServerApproveDisconnect');\n    });\n});\n/**\n * NAMESPACE /frontend\n * Channel through which new log records are pushed to the frontend.\n */\nfrontend.on('connect', (socket) => {\n    console.debug(`Frontend connected: ${socket.id}`);\n    socket.on('disconnect', () => {\n        console.debug(`Frontend disconnected: ${socket.id}`);\n    });\n    // TODO: send previous N logs from file on disk\n});\n// =================================================================================================\n// Start server on HTTP (and/or HTTPS).\nconst portHttp = process.env.SERVER_PORT_HTTP || 4000;\nserverHttp.listen(portHttp, () => {\n    console.log(`Server running at http://localhost:${portHttp}.`);\n});\n"]}