Open FarahZaqout opened 5 years ago
@FarahZaqout is this good farah ?
function handler(link, req, res) {
var endponit = req.url;
var pathName = {
home: ["/public/index.html",".."],
staticfle: [endponit,".."] ,
autocomplete: ["/Data/shortList.txt",""]
};
fs.readFile(path.join(__dirname, pathName[link][1], pathName[link][0]), function(err, file) {
if (err) {
console.error(err);
} else {
res.end(file);
}
});
}
https://github.com/FACG5/asi-autocomplete/blob/0f66d3d22af5ace2719bc050d614ef64b13e0c47/src/functions.js#L6-L56
These three functions can be abstracted into one. Give it a try, if you can't do it, give it a shot over the weekend too. This is the holy grail of writing clean, reusable and bug-free code.