#Unable to use any API URL with more than one parameter

3 messages · Page 1 of 1 (latest)

amber relic
#

My issue arose when I was following a tutorial for angular. This is an angular front end with a Hapi server. The server alone works fine, I can use the browser or curl to make requests to these endpoints with no problem. However, when using HttpClient to make a request from the frontend, it does not work as expected. I am using a proxy to not deal with cors issues, but from what I can tell the same issue occurs either way.

Example from service file:

    // return this.http.get<any>('/api/specific') // works
    return this.http.get<any>('/api/general/specific') //doesn't work
  }```

As seen in the comments, when making requests to /api/general or /api/specific or really /api/anything, it works no issues. However, if I try to nest another parameter in, such as in /api/general/specific, it does not work. It ends up returning my default app index.html page, which causes an error as JSON is expected. 

What could be causing this issue? Why does it not work as is? What can be done to make it work without doing something completely different? Is this just how it works?

The important code snippets can be found at this gist: https://gist.github.com/cisco95/bfe877f44610fcf641f738afbb414924
The full code is located here:
https://github.com/cisco95/angular-testapp
Gist

Issue when using API URL from front end. GitHub Gist: instantly share code, notes, and snippets.

GitHub

Contribute to cisco95/angular-testapp development by creating an account on GitHub.

#

Just to note, I did previously post a similar question for the same issue, but I have since narrowed down the issue and simplified the code to an MRE with less variables to the issue. Thanks in advance!

cedar bolt
#

I think the proxy config should be /api/**