/** * Fractafrag Renderer — Headless Chromium shader render service. * * Accepts GLSL code via POST /render, renders in an isolated browser context, * returns thumbnail + preview video. * * Full implementation in Track C. */ import express from 'express'; import { writeFileSync, mkdirSync, existsSync } from 'fs'; import path from 'path'; const app = express(); app.use(express.json({ limit: '1mb' })); const PORT = 3100; const OUTPUT_DIR = process.env.OUTPUT_DIR || '/renders'; const MAX_DURATION = parseInt(process.env.MAX_RENDER_DURATION || '8', 10); // Ensure output directory exists if (!existsSync(OUTPUT_DIR)) { mkdirSync(OUTPUT_DIR, { recursive: true }); } // Health check app.get('/health', (req, res) => { res.json({ status: 'ok', service: 'renderer' }); }); // Render endpoint (stub — Track C) app.post('/render', async (req, res) => { const { glsl, duration = 5, width = 640, height = 360, fps = 30 } = req.body; if (!glsl) { return res.status(400).json({ error: 'Missing glsl field' }); } // TODO: Track C implementation // 1. Launch Puppeteer page // 2. Inject GLSL into shader template HTML // 3. Capture frames for `duration` seconds // 4. Encode to WebM/MP4 + extract thumbnail // 5. Write to OUTPUT_DIR // 6. Return URLs res.status(501).json({ error: 'Renderer implementation coming in Track C', thumbnail_url: null, preview_url: null, }); }); app.listen(PORT, '0.0.0.0', () => { console.log(`Renderer service listening on :${PORT}`); console.log(`Output dir: ${OUTPUT_DIR}`); console.log(`Max render duration: ${MAX_DURATION}s`); });