Quick Start
Installation
Download & Run
git clone https://github.com/velox0/moonlight-server.git cd moonlight-server make build ./build/moonlight-server
Client Examples
HTTP Client (Node.js)
const http = require('http'); // Send heartbeat to register client async function sendHeartbeat() { const payload = { ip: '192.168.1.100', node_id: 'node-001', token: 'supersecrettokenox0', region: 'us-east-1', port: 3000 }; const res = await postJSON('/client/heartbeat', payload); console.log('Heartbeat response:', res.status); } // Send heartbeat every 15 seconds sendHeartbeat(); setInterval(sendHeartbeat, 15000);
WebSocket Client
const WebSocket = require('ws'); const express = require('express'); const app = express(); app.use(express.json()); // Handle tasks from Moonlight server app.post('/work', (req, res) => { const { payload } = req.body; // Process the task const result = { processed: true, data: payload }; res.json({ status: 'completed', result: result }); }); app.listen(3000, () => console.log('Client listening on port 3000')); const client = new WebSocket('ws://localhost:8080/ws'); client.on('open', () => { // Register client client.send(JSON.stringify({ type: 'register', payload: { ip: '192.168.1.100', node_id: 'node-002', token: 'supersecrettokenox0', region: 'us-west', port: 3000 } })); }); client.on('message', (data) => { const message = JSON.parse(data); console.log('Received:', message); });
Test Connection
# Register client via HTTP curl -X POST http://localhost:8080/client/heartbeat \ -H "Content-Type: application/json" \ -d '{ "ip": "192.168.1.100", "node_id": "test-node", "token": "supersecrettokenox0", "region": "global", "port": 3000 }'
Task Workflow
Clients receive tasks on their /work
endpoint. Send task requests to Moonlight server which forwards them to available clients.
Send Task Request
# Send task to specific region curl -X POST http://localhost:8080/task/request \ -H "Content-Type: application/json" \ -d '{ "region": "global", "payload": { "action": "process_data", "data": {"message": "hello world"} } }'
Client Task Handler
// Client must implement /work endpoint app.post('/work', (req, res) => { const { payload } = req.body; // Process the task const result = processTask(payload); res.json({ status: 'completed', result: result }); });