@nodefony/monitoring-bundle
Version:
Nodefony Framework Bundle Monitoring
98 lines (92 loc) • 2.87 kB
JavaScript
/**
* The class is a **`default` CONTROLLER** .
* @module NODEFONY
* @main NODEFONY
* @class defaultController
* @constructor
* @param {class} container
* @param {class} context
*
*/
module.exports = class defaultController extends nodefony.controller {
constructor(container, context) {
super(container, context);
}
indexAction(module) {
if (module) {
this.response.setHeader('Content-Type', "application/xml");
if (module === "app") {
let bundles = function () {
let obj = {};
for (let bundle in this.kernel.bundles) {
obj[bundle] = {
name: this.kernel.bundles[bundle].name,
version: this.kernel.bundles[bundle].settings.version,
config: this.container.getParameters("bundles." + bundle)
};
}
return obj;
}.call(this);
return this.render('monitoringBundle::' + module + '.xml.twig', {
bundles: bundles,
user: this.context.user
}).catch(e=>{
this.log(e,"ERROR");
this.response.setHeader('Content-Type', "text/html");
return this.createNotFoundException();
});
}
return this.render('monitoringBundle::' + module + '.xml.twig')
.catch(e=>{
this.log(e,"ERROR");
this.response.setHeader('Content-Type', "text/html");
return this.createNotFoundException();
});
} else {
return this.render('monitoringBundle::index.html.twig', {
environment: this.kernel.environment,
debug: this.kernel.debug
}).catch(e=>{
this.log(e,"ERROR");
this.response.setHeader('Content-Type', "text/html");
return this.createNotFoundException();
});
}
}
/**
*
*
*
*
**/
realTimeAction(message) {
let realtime = this.get("realTime");
let context = this.getContext();
switch (this.getRequest().method) {
case "GET":
return this.getResponse("PING");
case "POST":
return realtime.handleConnection(this.getParameters("query").request, context);
case "WEBSOCKET":
if (message) {
realtime.handleConnection(message.utf8Data, context);
}
break;
default:
throw new Error("REALTIME METHOD NOT ALLOWED");
}
}
testLoadAction(message) {
let context = this.getContext();
let serverLoad = this.get("serverLoad");
switch (this.getRequest().method) {
case "WEBSOCKET":
if (message) {
serverLoad.handleConnection(JSON.parse(message.utf8Data), context);
}
break;
default:
throw new Error("REALTIME METHOD NOT ALLOWED");
}
}
};