1

I am running a REST server on http://localhost:8080, my Aurelia app on http://localhost:9000 and want to access the server with aurelia-fetch-client. I fail miserably already with the URL: For reasons I don't understand, the Aurelia host:port combination gets prefixed. The request URL turns out to be:

http://localhost:9000/localhost:8080/restapi/v1/things

But obviously I want:

http://localhost:8080/restapi/v1/things

Configuration:

let httpClient = new HttpClient();
httpClient.configure(config => {
  config
    .withBaseUrl('http:/localhost:8080/restapi/v1/')
    .withDefaults({
      credentials: 'omit',
      mode: 'cors',
    });
});

Call:

return httpClient
  .fetch('things', {
    method: 'get'
  })
...

I have expected to run into all kind of CORS trouble, but that I cannot even get the URL right is a bit disappointing :-)

Does anybody see what I am doing wrong?

Ideally I would like to bypass CORS completely, i.e. not having to enable the REST server for CORS. But at this point I'd already be happy if the URL came out right.

StaticNoiseLog
  • 1,370
  • 17
  • 27
  • 2
    My initial instinct is just a small typo to start with: `.withBaseUrl('http:/localhost:8080/restapi/v1/')`... needs to be `http://` – Nick Jan 08 '18 at 13:13
  • 1
    OMG!!!! Thanks Nick! I had messed this up somewhere along the way in my code (not just in the posting). This indeed causes the Aurelia library to prefix the (non-)URL with the host:port combination of the Aurelia app. Strange effect. Feel free to write a response, I will accept it. – StaticNoiseLog Jan 08 '18 at 14:42
  • 1
    No problem, it's exactly the kind of thing all of us miss when we've been staring at code for hours. Good luck with the CORS issue; my instinct is you're not going to circumvent CORS unless it's acceptable to bundle your Aurelia app and serve it from your REST server as well, therefore putting it on the same port. – Nick Jan 09 '18 at 15:11

1 Answers1

2

As discussed in our comment thread, there's a small typo (missing a / after http:) causing the malformed URL.

withBaseUrl('http://localhost:8080/restapi/v1/')
Nick
  • 16,066
  • 3
  • 16
  • 32