cmda-bt / be-course-17-18

🎓 Backend · 2017-2018 · Curriculum and Syllabus 💾
Other
47 stars 19 forks source link

Listing assignment #497

Closed maanlamp closed 6 years ago

maanlamp commented 6 years ago

Static file server

I think I did way too much, if there is such a thing 😄.

I did really like this assignment, albeit very difficult. Or perhaps i made it difficult... Oh well. In some cases it crashes and burns very violently because I generally have no idea what I'm doing, and also because urls are the worst 🤷‍♂️.

Other than that, I think it works perfectly.

🔗 Check out the repo

wooorm commented 6 years ago

Sweet!

wooorm commented 6 years ago

ahh I pressend send too early, but anyway, here it is!

maanlamp commented 6 years ago

tip: don’t use custom fonts, especially in a small 404 page, they take a while to load

Yep, I could've downloaded it but I was too lazy 😋

Don’t include your node modules, except for your own server-response, but I suggest placing that in the root of your project instead of in node_modules

Hah, whoops, forgot to .gitignore those 😅

you should look into using a javascript code-style linter!

Because I'm all over the place? Or because my style sucks? hahaha

what’s this whole bit doing?

const alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
const groupedFiles = {};
for (const letter of alphabet) {
    groupedFiles[letter] = (files.filter(file => {
        return file[0].toLowerCase() === letter;
    }));
}

I wanted to do some fancy styling and sorting of the list of files. Because fs.readdir just gives an array of strings back, I couldn't sort the results by letter (at least not without some js). So to start I declare the alphabet as an array. Then, for every letter in that array, I set the value of te key to a filtered file array I got from fs.readdir. So I have the object groupedFiles, which gets a key for every letter of the alphabet, and every key contains an array with only strings that begin with the same letter as the key, i.e.:

{a: [adobe, amd], b: [], c: [chrome]}

I hope that made sense because I don't even understand my own explanation. Anyway, I needed that to make those fancy lists sorted and filtered alphabetically.

In the getFileStats, I suggest returning null for unfound things: false is a boolean, and suggest a value could also be true, but null is specifically an unfound value!

Yep, sloppy code. I just wanted to get it overwith at that point 😅 Hadn't thought about it.

Is the utf8 in .toString("utf8") needed?

I can't fully remember, but I think it was. I seem to recall the function returning a buffer when calling the toString method. Really weird...

wooorm commented 6 years ago

Oh an finally, seems the count is always 26!

screen shot 2018-03-06 at 08 20 41 screen shot 2018-03-06 at 08 20 49

maanlamp commented 6 years ago

Ah right, without looking at my code I can tell why that's happening I think. I just send the amount of keys of the groupedFiles object to the filder.html template, but it always has 26 keys (1 for every letter of the alphabet). I probably should .reduce() it and count only keys with a non-emtpy array value.

Done 💪 Fixed a lot of points you made. Thanks for helping me improve!