UNPKG

legendaryjs

Version:

LegendaryJS – The ultimate backend framework for speed, power, and simplicity.

48 lines (41 loc) 1.39 kB
const fs = require('fs'); function applyRepairLogic(app, io) { app.use((err, req, res, next) => { console.warn(`🛠️ Self-Healing: ${err.message}`); if (res.headersSent) return next(err); res.status(500).json({ message: "Internal Server Error", repair: true }); }); const check = { routes() { try { const routes = require(fs.existsSync('./routes/api.v1.json') ? './routes/api.v1.json' : './fallback/routes.json'); return !!routes.routes; } catch { console.warn('⚠️ Self-Healing: routes/api.v1.json corrupted or missing. Using fallback.'); return false; } }, mongo() { if (!process.env.MONGO_URI) { console.warn('⚠️ Self-Healing: MONGO_URI is missing. MongoDB may fail to connect.'); } }, jwt() { if (!process.env.JWT_SECRET) { console.warn('⚠️ Self-Healing: JWT_SECRET is missing. Tokens will not validate properly.'); } } }; Object.keys(check).forEach(c => check[c]()); if (io) { io.of('/dashboard').on('connection', socket => { socket.emit('repair-info', { message: '🛠 Self-Healing Engine active. Monitoring runtime failures...' }); }); } console.log('🛠 Self-Healing Engine v2 ready'); } module.exports = { applyRepairLogic };