peetzweg / aves

0 stars 0 forks source link

Find a unique identifier for a Article #9

Closed peetzweg closed 7 years ago

peetzweg commented 7 years ago

At first I thought I could easily extract the origin of a request via the API Gateway, however, up until now I haven't find a way to do that. So for now I will just pass the origin myself in a decoded way to overcome transport issues.

The Id needs to be base64 and URI encoded, so it can be passed via a body property as well as a query string.

To do this in Javascript one needs to perform the following

var id ="https://www.madewithtea.com/minimalism-the-art-of-living-with-less.html";
var idBase64 = btoa(id); // btoa() only usable in front end environment
var idBase64URI = encodeURIComponent(idBase64);
idBase64 == decodeURIComponent(idBase64URI)
id == new Buffer(idBase64, 'base64').toString('ascii'); // atob() function is not available in node
peetzweg commented 7 years ago

Just shifted to host and pathname from the document.location object. This way it does not take any queries into account as well as the port and protocol. Way easier.