Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using remote service instead of local root #53

Open
kgish opened this issue Jan 6, 2015 · 3 comments
Open

Using remote service instead of local root #53

kgish opened this issue Jan 6, 2015 · 3 comments

Comments

@kgish
Copy link

kgish commented Jan 6, 2015

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
Copy link
Author

kgish commented Jan 6, 2015

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
  ...
};
...

@xogeny
Copy link

xogeny commented Feb 2, 2015

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
Copy link

xogeny commented Feb 2, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants