Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.on("error",(err)=>{
Log.error("Error on HTTPS Server on "+hostname+":"+port+":",err);
});
catch (ex) {
Log.error("Error in routing for "+url+".",ex);
return reject(ex);
}
};
nextRoute();
});
if (!response.finished) {
Log.error("404 Not found "+url+".");
await response.writeError(404,"404 Not found "+url+".");
}
}
catch (ex) {
Log.error("Error handling request "+url+".",ex);
response.writeError(500,"Error handling request "+url+".");
}
}
}
if (!clazz) {
Log.error("Loaded controller not found "+filename);
throw new Error("Loaded controller not found "+filename);
}
else if (clazz instanceof Function && Object.prototype.isPrototypeOf.call(AbstractController,clazz)) {
let instance;
try {
instance = Reflect.construct(clazz,additionalArgs);
}
catch (ex) {
Log.error("Error instantiating controller.",ex);
throw ex;
}
if (!(instance instanceof AbstractController)) {
Log.error("Loaded controller does not extend AbstractController "+filename);
throw new Error("Loaded controller does not extend AbstractController "+filename);
}
if (this.config.informative) Log.info("Loaded controller from "+filename+".");
_routeController.call(this,route,instance);
}
else if (clazz instanceof AbstractController) {
if (this.config.informative) Log.info("Loaded controller from "+filename+".");
_routeController.call(this,route,clazz);
}
else {
Log.error("Loaded controller does not extend AbstractController "+filename);
throw new Error("Loaded controller does not extend AbstractController "+filename);
}
return route;
catch (ex) {
Log.error("Error loading controller "+filename,ex);
throw ex;
}
if (!clazz) {
Log.error("Loaded controller not found "+filename);
throw new Error("Loaded controller not found "+filename);
}
else if (clazz instanceof Function && Object.prototype.isPrototypeOf.call(AbstractController,clazz)) {
let instance;
try {
instance = Reflect.construct(clazz,additionalArgs);
}
catch (ex) {
Log.error("Error instantiating controller.",ex);
throw ex;
}
if (!(instance instanceof AbstractController)) {
Log.error("Loaded controller does not extend AbstractController "+filename);
throw new Error("Loaded controller does not extend AbstractController "+filename);
}
if (this.config.informative) Log.info("Loaded controller from "+filename+".");
_routeController.call(this,route,instance);
}
else if (clazz instanceof AbstractController) {
if (this.config.informative) Log.info("Loaded controller from "+filename+".");
_routeController.call(this,route,clazz);
}
else {
Log.error("Loaded controller does not extend AbstractController "+filename);
server.on("error",(err)=>{
Log.error("Error on HTTP/2 Server on "+hostname+":"+port+":",err);
});
static resolveCertConfig(value,type="certificate",informative=true) {
if (value && typeof value==="string" && !value.startsWith("----")) {
let filename = Path.resolve(process.cwd(),value);
if (informative) Log.info("Loading "+type+" from "+filename+".");
if (AwesomeUtils.FS.existsSync(filename)) {
try {
let pfx = FS.readFileSync(filename);
if (!pfx) throw new Error(type+" file empty: "+filename+".");
value = pfx;
}
catch (ex) {
Log.error("Error reading "+type+" from "+filename+".",ex);
}
}
else {
Log.error(type+" file not found: "+filename+".");
}
}
else if (value) {
if (informative) Log.info("Using passed contents for "+type+" value.");
}
return value;
}
}
const _routeFile = function routeControllerFile(route,filename,additionalArgs=[]) {
let clazz;
try {
clazz = AwesomeUtils.Module.require(filename);
}
catch (ex) {
Log.error("Error loading controller "+filename,ex);
throw ex;
}
if (!clazz) {
Log.error("Loaded controller not found "+filename);
throw new Error("Loaded controller not found "+filename);
}
else if (clazz instanceof Function && Object.prototype.isPrototypeOf.call(AbstractController,clazz)) {
let instance;
try {
instance = Reflect.construct(clazz,additionalArgs);
}
catch (ex) {
Log.error("Error instantiating controller.",ex);
throw ex;
}
if (value && typeof value==="string" && !value.startsWith("----")) {
let filename = Path.resolve(process.cwd(),value);
if (informative) Log.info("Loading "+type+" from "+filename+".");
if (AwesomeUtils.FS.existsSync(filename)) {
try {
let pfx = FS.readFileSync(filename);
if (!pfx) throw new Error(type+" file empty: "+filename+".");
value = pfx;
}
catch (ex) {
Log.error("Error reading "+type+" from "+filename+".",ex);
}
}
else {
Log.error(type+" file not found: "+filename+".");
}
}
else if (value) {
if (informative) Log.info("Using passed contents for "+type+" value.");
}
return value;
}
}
const nextRoute = async function nextRoute() {
try {
if (response.finished) return resolve();
let route = routes.shift();
if (!route) return resolve();
let pathOrParams = route.path;
if (route.result && route.result!==true) pathOrParams = route.result;
let p = route.router.call(this,pathOrParams,request,response);
if (p instanceof Promise) await p;
setImmediate(nextRoute);
}
catch (ex) {
Log.error("Error in routing for "+url+".",ex);
return reject(ex);
}
};
if (value && typeof value==="string" && !value.startsWith("----")) {
let filename = Path.resolve(process.cwd(),value);
if (informative) Log.info("Loading "+type+" from "+filename+".");
if (AwesomeUtils.FS.existsSync(filename)) {
try {
let pfx = FS.readFileSync(filename);
if (!pfx) throw new Error(type+" file empty: "+filename+".");
value = pfx;
}
catch (ex) {
Log.error("Error reading "+type+" from "+filename+".",ex);
}
}
else {
Log.error(type+" file not found: "+filename+".");
}
}
else if (value) {
if (informative) Log.info("Using passed contents for "+type+" value.");
}
return value;
}
}