Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.3k stars 3.33k forks source link

More graceful fallback when URL shortening not available #677

Closed stevage closed 11 years ago

stevage commented 11 years ago

After a bit of investigation, I've discovered that the reason that URL shortening doesn't work for my hosted version is basically because map.project-osrm.org's URL shortening service doesn't support shortening for random other servers.

Unfortunately, this isn't really obvious. And there's no easy workaround - I have to either find some other URL shortening service that uses jsonp and doesn't require authentication, or run one myself.

Secondly, although OSRM does support permanent links (ie, what the shortened URL resolves to), there doesn't seem to be any obvious way to get to them.

So, suggestion:

  1. By default, have "Generate link" just provide an unshortened link.
  2. Have the code for shortened links commented out, with the warning that it won't work if you try to use map.project-osrm.org

And:

  1. Consider including URL shortening code. How hard can it be, like 5 lines of code? :)
DennisOSRM commented 11 years ago

Patches welcome!

DennisSchiefer commented 11 years ago

The next upload will contain minor code support for using non-shortened links. But shortened links will remain the default case.

That said, the fixes are really minor, and for a good integration you will have to do some additional work by yourself. For example, a customizable text is displayed instead of the shortened URL, but translations are not provided. Also, our QR code is set to version 4 with high error corrrection. This means, only up to 34 8bit characters are supported. A full URL will always be much longer. Thus, if you wish to use QR codes, you'd have to change the QR version appropriately as well as the size of the pop-up window.

stevage commented 11 years ago

Btw here's what I did to get URL shortening working, in case you want to include this as a comment, or in docs or whatever.

  1. Get an API key from tiny-url.info: http://www.tiny-url.info/request_api_key.html
  2. Replace these three settings in OSRM.config.js:

    HOST_SHORTENER_URL: 'http://tiny-url.info/api/v1/create/?',
    SHORTENER_PARAMETERS: 'callback=%jsonp&format=json&apikey=A123....&provider=bit_ly&url=%url',
    SHORTENER_REPLY_PARAMETER: 'shorturl',

  3. Change this line in OSRM.RoutingDescription.js:

    var source = OSRM.DEFAULTS.HOST_SHORTENER_URL + OSRM.DEFAULTS.SHORTENER_PARAMETERS.replace(/%url/, encodeURIComponent(src));

DennisSchiefer commented 11 years ago

Okay, scratch my last comment. the next upload will have full support for not using a shortener service and dynamically sized QR codes

stevage commented 11 years ago

Great :)