alanshaw / david-www

:eyeglasses: David helps keep your Node.js project dependencies up to date.
https://david-dm.org
MIT License
730 stars 131 forks source link

Feature: simplifying URLs by relying on Referer header? #356

Open makii42 opened 7 years ago

makii42 commented 7 years ago

While adding some dependency badges to repos, I was wondering why there is the necessity to specify user/org and repo name in the URL, as ideally this information is already passed via the Referer header.

It should be possible to expose a route for the badges as well the link to the package dependencies page by taking a look at the referrer. One would have to extracts the right portions, which according to badge.js are

and generate a redirect to either the appropriate existing image- or page-route. Thinking about it, there are probably some pros and cons to do that. This is my first pass:

pros:

cons:

That's all I can come up with for now.

What would need to be done:

What do you think about this feature? Would a contribution implementing this be welcome?

alanshaw commented 7 years ago

That's a really interesting proposition and I'd love to see a pull request for this! My only hesitation is the extra traffic, since the service currently really struggles when response time from the npm/github APIs slows. So, encouraging more traffic on top of this might be problematic right now. However don't let that stop you - this is a brilliant idea and I'd love to see it happen :rocket: 😍

alanshaw commented 7 years ago

Just a thought, we should check the github proxy passes on the Referer header (I don't know why it wouldn't but worth a check before you start the work!)

makii42 commented 7 years ago

So, the first pass is there, and instantaneously I found the first downside: This won't work in all contexts, e.g. on npmjs.com, as the Referer in this case only contains the package name, and the parse logic is still as dumb as possible right now, requiring a github.com-style URL.

Depending on how much logic is supposed to be on the server side, a resolution of such specific referrers is not impossible, but cumbersome, as it will require additional lookups, either local (if e.g. the package.json contents are present) or remote.