Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.stream.stream.on("error",()=>{
// this event handler must be here or node will die when the error gets swallowed by http2.
// See https://github.com/nodejs/node/issues/22323
Log.warn("The client refushed the push stream for "+this.headers[":path"]+".");
});
}
let path,route;
if (arg==="." || arg==="/" || arg==="./") {
path = cwd;
route = "/*";
}
else {
path = Path.resolve(cwd,arg);
route = ("/"+path.slice(cwd.length+1)).replace(/\/\.\//,"/");
}
if (path && route && AwesomeUtils.FS.existsSync(path)) {
server.serve(route,path);
Log.info("Serving "+route+" from "+path);
}
else {
Log.warn("Path "+arg+" did not resolve to a valid file or directory; skipping.");
return;
}
});
}
return new Promise(async (resolve,reject)=>{
try {
if (!path || path==="/") path = "index.html";
let filename = Path.resolve(this.dir,path);
let stat = await AwesomeUtils.FS.stat(filename);
if (!stat) {
Log.warn("File not found: "+path);
response.writeError(404,"File not found: "+path);
return resolve();
}
if (stat && stat.isDirectory()) {
filename = Path.resolve(path,"./index.html");
let dirstat = await AwesomeUtils.FS.stat(filename);
if (!dirstat) {
Log.warn("File not found: "+path);
response.writeError(404,"File not found: "+path);
return resolve();
}
}
let contentType = AwesomeUtils.MimeTypes.getTypeForExtension(filename,"application/octet-stream");
await response.serve(200,contentType,filename);
async start() {
if (this.running) return Promise.resolve();
if (this.config.informative) Log.info("Starting...");
if (this[$SERVERS].size<1) {
Log.warn("No servers defined. Nothing to do.");
}
else {
await Promise.all([...this[$SERVERS]].map((server)=>{
let prom = server.start(this.handler.bind(this));
if (prom instanceof Promise) return prom;
return Promise.resolve();
}));
}
this[$RUNNING] = true;
if (this.config.informative) Log.info("Started.");
}