legendaryjs
Version:
LegendaryJS – The ultimate backend framework for speed, power, and simplicity.
49 lines (40 loc) • 1.56 kB
JavaScript
const fs = require('fs');
const path = require('path');
const express = require('express');
const { getStats } = require('../tools');
function setupStudio(app, io) {
const studioPath = path.join(__dirname, '../studio');
app.use('/legendary-studio', express.static(studioPath));
// GET routes.json
app.get('/studio/routes', (req, res) => {
const file = path.join(process.cwd(), 'routes/api.v1.json');
if (!fs.existsSync(file)) return res.json({ routes: [] });
const data = JSON.parse(fs.readFileSync(file));
res.json(data);
});
// POST routes.json
app.post('/studio/routes', express.json(), (req, res) => {
const file = path.join(process.cwd(), 'routes/api.v1.json');
fs.writeFileSync(file, JSON.stringify(req.body, null, 2));
res.json({ success: true });
});
// POST legendary.config.js (stringified)
app.post('/studio/config', express.json(), (req, res) => {
const configPath = path.join(process.cwd(), 'legendary.config.js');
fs.writeFileSync(configPath, req.body.js);
res.json({ success: true });
});
// Socket.io for studio
io.of('/studio').on('connection', (socket) => {
console.log('🧠 Studio connected:', socket.id);
socket.emit('stats', getStats());
const interval = setInterval(() => {
socket.emit('stats', getStats());
}, 2000);
socket.on('disconnect', () => {
console.log('📴 Studio disconnected:', socket.id);
clearInterval(interval);
});
});
}
module.exports = { setupStudio };