hal-browser icon indicating copy to clipboard operation
hal-browser copied to clipboard

Using remote service instead of local root

Open kgish opened this issue 10 years ago • 3 comments

Rather than use the hal browser from the root directory I would prefer to point it to a remote service, e.g. localhost:8080 how can I do this?

kgish avatar Jan 06 '15 09:01 kgish

I found out where to hack it, but you probably want a more elegant fix that is configurable.

In the file client.js see the lines marked <== FIXED

...
HAL.Http.Client.prototype.get = function(url) {
  var self = this;
  this.vent.trigger('location-change', { url: url });
  var jqxhr = $.ajax({
    url: 'http://localhost:8080'+url, // <== FIX
    dataType: 'json',
    success: function(resource, textStatus, jqXHR) {
    ...
  });
};

HAL.Http.Client.prototype.request = function(opts) {
  var self = this;
  opts.dataType = 'json';
  opts.url ='http://localhost:8080'+opts.url; // <== FIX
  ...
};
...

kgish avatar Jan 06 '15 15:01 kgish

Isn't the "correct" answer here to follow Section 5 "Reference Resolution" of RFC 3986 "Uniform Resource Identifier (URI): Generic Syntax"?

The main issue, if I understand it, is establishing a base URI. But if I visit:

http://haltalk.herokuapp.com/explorer/browser.html#http://localhost:3000

It seems clear that the base URI is http://localhost:3000 (since that is the URI that the request was made to). So if the response from http://localhost:3000 includes a link of the form /foo, shouldn't that be normalized into "http://localhost:3000/foo". The current version on Heroku simply attempts to use /foo (which, I take it, is the issue you are concerned about?).

xogeny avatar Feb 02 '15 15:02 xogeny

OK, so I had this same issue and I wasn't really able to test my API because it lacks support for handling relative URIs in the HAL API. The changes required are not actually in client.js. The reason is that you need to have some context and client.js doesn't have that. But I looked through the code and I adjusted things so that it resolves relative URIs at the time it renders the page in browser.html.

I've submitted a pull request to adds support for relative URIs for anyone who is interested.

xogeny avatar Feb 02 '15 16:02 xogeny