35 lines
917 B
JavaScript
35 lines
917 B
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const fs = require('fs');
|
|
const config = require('../../config');
|
|
|
|
router.get('/', (req, res) => {
|
|
const health = {
|
|
status: 'healthy',
|
|
timestamp: new Date().toISOString(),
|
|
uptime: process.uptime(),
|
|
scriptalizer: config.scriptalizer.licenseKey ? 'configured' : 'missing',
|
|
storage: {
|
|
cache: fs.existsSync(config.paths.cache) && isWritable(config.paths.cache),
|
|
output: fs.existsSync(config.paths.output) && isWritable(config.paths.output)
|
|
}
|
|
};
|
|
|
|
const allHealthy = health.scriptalizer === 'configured' &&
|
|
health.storage.cache &&
|
|
health.storage.output;
|
|
|
|
res.status(allHealthy ? 200 : 503).json(health);
|
|
});
|
|
|
|
function isWritable(path) {
|
|
try {
|
|
fs.accessSync(path, fs.constants.W_OK);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
module.exports = router;
|