Initial commit
This commit is contained in:
34
Docker Backend/src/api/routes/health-routes.js
Normal file
34
Docker Backend/src/api/routes/health-routes.js
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user