implement proper nodejs debugging
- will start to phase out using console.log for actual debugging - existing "debug" (verbose) messages will stay as is - future code debugging will use debug() to debug WIP, therefore not showing to most users if it is accidently left in
This commit is contained in:
@@ -22,6 +22,7 @@ const WTVClientSessionData = require(classPath + "/WTVClientSessionData.js");
|
|||||||
const WTVMime = require(classPath + "/WTVMime.js");
|
const WTVMime = require(classPath + "/WTVMime.js");
|
||||||
const WTVFlashrom = require(classPath + "/WTVFlashrom.js");
|
const WTVFlashrom = require(classPath + "/WTVFlashrom.js");
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
|
const debug = require('debug')('minisrv_main');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
var wtvnewsserver = null;
|
var wtvnewsserver = null;
|
||||||
|
|
||||||
@@ -182,12 +183,26 @@ async function sendRawFile(socket, path) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var runScriptInVM = function (script_data, user_contextObj = {}, privileged = false, filename = null) {
|
var runScriptInVM = function (script_data, user_contextObj = {}, privileged = false, filename = null, debug_name = null) {
|
||||||
// Here we define the ServiceVault Script Context Object
|
// Here we define the ServiceVault Script Context Object
|
||||||
// The ServiceVault scripts will only be allowed to access the following fcnutions/variables.
|
// The ServiceVault scripts will only be allowed to access the following fcnutions/variables.
|
||||||
// Furthermore, only modifications to variables in `updateFromVM` will be saved.
|
// Furthermore, only modifications to variables in `updateFromVM` will be saved.
|
||||||
// Example: an attempt to change "minisrv_config" from a ServiceVault script would be discarded
|
// Example: an attempt to change "minisrv_config" from a ServiceVault script would be discarded
|
||||||
|
|
||||||
|
// try to build a name for the script's debug() calls
|
||||||
|
if (!debug_name) {
|
||||||
|
// try to make the debug name
|
||||||
|
var debug_name = (filename) ? filename.split(path.sep) : null;
|
||||||
|
if (debug_name) {
|
||||||
|
if (wtvshared.isConfiguredService(debug_name[debug_name.length - 2]))
|
||||||
|
// service:/filename
|
||||||
|
debug_name = debug_name[debug_name.length - 2] + ":/" + debug_name[debug_name.length - 1];
|
||||||
|
else
|
||||||
|
// filename
|
||||||
|
debug_name = debug_name[debug_name.length - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create global context object
|
// create global context object
|
||||||
var contextObj = {
|
var contextObj = {
|
||||||
// node core variables and functions
|
// node core variables and functions
|
||||||
@@ -210,6 +225,7 @@ var runScriptInVM = function (script_data, user_contextObj = {}, privileged = fa
|
|||||||
"path": path,
|
"path": path,
|
||||||
|
|
||||||
// Our variables and functions
|
// Our variables and functions
|
||||||
|
"debug": require('debug')((debug_name) ? debug_name : 'service_script'),
|
||||||
"minisrv_config": minisrv_config,
|
"minisrv_config": minisrv_config,
|
||||||
"socket": null,
|
"socket": null,
|
||||||
"headers": null,
|
"headers": null,
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ class WTVShared {
|
|||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isConfiguredService(service) {
|
||||||
|
if (this.minisrv_config.services[service]) {
|
||||||
|
if (!this.minisrv_config.services[service].disabled) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
getServiceString(service, overrides = {}) {
|
getServiceString(service, overrides = {}) {
|
||||||
// used externally by service scripts
|
// used externally by service scripts
|
||||||
if (service === "all") {
|
if (service === "all") {
|
||||||
|
|||||||
Reference in New Issue
Block a user