Express Makro Node Programming

Just Expressing myself

Unfortunately I haven’t really had time to make that much progress with Makro lately since other parts of my life have been keeping me a bit busy. But fear not, though. I have made some progress nevertheless. I did do the profile page redesign but not the admin page. The redesign for admin page isn’t really a high priority task since I am the only admin so it doesn’t really matter what it looks like because I’ll be the only one looking at that.

The profile page is now divided to 5 sections: user information, planned days, shared meals, added foods and Q&A. From those the Q&A part is divided to four sections: questions, answers, comments and likes. I wanted to do this resign because the profile page was getting a bit too cluttered and opening it would make a plenty of API calls even if the user wanted to his/her information. Don’t want to overload my little Node server.

Besides that I have fixed some UI bugs and added one new feature that a user requested which was the possibility to copy food from a meal to another. But that functionality is not quite finished yet since I want users to be able to just drag the food to another meal to copy it so it would be a bit faster. Now it’s done via modal by selecting the food you want to copy and the meal you want to copy it to. I only made it that way first because I just couldn’t figure out the UI for it yet and didn’t really have time to think about it too long. The space for the so called meal table is limited and quite full as is so adding new buttons just makes it cramped. But I’ll make it work in the future. Funny thing is that the actual implementation is not the hardest part at the moment but the UI design.

What else? The code base is a bit over 11k LoC now. Yeah I know. It’s a rather pointless thing to look at but hey it’s something.

Oh yeah and one thing before I forgot to mention it. I finally fixed a bug that prevented unregistered users to not be able to access (or rather get) the day shared via link. It always returned unauthorized even though I had not intended to do that.

I had a method on routes related to sharing days that would check if the user can access the resource or not.

if (req.path.includes(‘/pathtogettheday/’) && req.method === ‘GET’) {

} else {




When I started debugging I noticed that that method was never executed for some reason. That was really confusing because the routes that were supposed to be protected actually were protected. So what gives? surprise

The fault here was a combination of my laziness and how Express handles routing. Because I was lazy I had defined my most of my routes to be at /api/v1/theactualroute which led to that Express used the first route (file, which in this case was foods) to check the authorization. There was only one route that wasn’t protected which sure didn’t forget the shared day and thus returned the unauthorized error if the user was not logged in. After discovering that the fix was quite simple: I just had to define my routes like a sane person would do. So instead everything being behind /api/v1/ they are now divided like the should’ve been from the beginning. So for example, if you want to get the foods you would make the call to /api/v1/foods/ and so on.

The things you learn by making stupid mistakes.

PS. I have had this site (the Django version of it at least) since April and it took me this long to find the emojis.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top