Luciano Mammino 💛 Node.js
+ Your AuthorsArchive @loige I tweet about Cloud Web development, #Nodejs & #JavaScript. I am co-author of & maintainer of Oct. 18, 2020 3 min read

#MVPin7Days DAY 6 & 7 - Weekend EDITION 🍻

As anticipated I invested a few spare hours yesterday and today to add the actual redirect logic which completes what I wanted to achieve for this week! 🥳

The best thing I can do to celebrate this personal milestone is to show you a full demo of what the product can do so far... and surprise, surprise 🥁 it's going to be a very short demo! 😅

What's happening in the video is the following:

- I can create a link for an
#Amazon product (#Halloween mood here 🎃)
- Once I visit that link I get redirected to the closest Amazon store to me (in my case: Ireland -> Amazon UK)

You can see that if I change country (thank you @expressvpn) I get redirected to different Amazon stores. Also note that for Canada, that specific product is not available and in this case, I see a search page for similar products.

That's it!

Now let's talk about technical challenges, my favourite part! 🤗

Writing the code to manage the redirect was actually surprisingly easy. It's not a small amount of code, but I managed to write it all down quite quickly and it "seemed" to work straight away locally.

This was probably easy for me because recently I spent some time writing something similar, which is actually open-source and you can check out in the links below if you are really curious 😜

(give it a ⭐️, will you?)


Well... when something seems too easy at first, there is often a trap lurking behind the corner...

In fact, as soon as I deployed the latest version of the app, the redirect logic didn't seem to select the expected Amazon shop and it was redirecting me always to the default (Amazon [dot] com!)...

Turns out that this was a combination of a few different configuration issues on the #nginx side and on #fastify side.

Before I get into the specifics let me tell you that my current setup is roughly the following:

With this setup, by default, Fastify was not seeing the actual user IP and therefore the business logic was failing to detect the user location.

The way you fix this type of issue is by adding the X-Forwarded-For header, of which you can read more here: 

This header needs to be added by Nginx when forwarding the request to Fastify.

After a lot of fiddling I found out the correct config for Nginx:

( )

On the Fastify side, Fastify needs to be aware that it should not rely on the TCP connection source IP, but instead it should look into that X-Forwarded-For HTTP header.

Fastify can actually do this very easily, by enabling the following option:

( )

When this was sorted out everything worked as expected and I could finally be happy 😀

So, this completes my week!
I am quite happy with the results so far, but what's next?

This is indeed a good question! 🤔👋💀

To be honest, I haven't formulated any decent plan yet and I am aware that starting from tomorrow I will have a very limited amount of time to work on this idea...

Nonetheless, I would like to bring this idea to a slightly better shape so I can validate if it can actually be useful to people!

I want to add some important missing features (e.g. users right now can't even see the list of links they created already!) and clean up the UX a bit

At that point, once I have some feedback, I'll be able to decide whether this idea is something worth pursuing or not!

Sounds simple, in theory, by stay tuned to know how it will turn out in practice. 😝

Also, if you know anyone that makes money with the Amazon Affiliates program do let me know, they might be interested to give this idea a shot (and give me some good piece of feedback!)

That's all for today and for this week!

Thanks for staying with me so far! 😍

Enjoy the rest of your weekend ❤️


You can follow @loige.


Tip: mention @threader_app on a Twitter thread with the keyword “compile” to get a link to it.

Threader is an independent, ad-free project created by two developers. Our iOS Twitter client was featured as an App of the Day by Apple. Sign up today to compile, bookmark and archive your favorite threads.

Follow Threader