The proxy seems to be working properly when I make a http request to /api, but if I make a request to /api/ticker then the browser will just request http://ticker. @hich is where I get the net::ERR_NAME_NOT_RESOLVED error in the console.
So my question is, when requesting /api/ticker Shouldn’t the proxy be switching the url to https://api.coinmarketcap.com/v1/ticker?
GET http://localhost:8100/v1/ticker 404 (Not Found)
and from the network tab:
Request URL:http://localhost:8100/v1/ticker Request Method:GET Status Code:404 Not Found Remote Address:127.0.0.1:8100 Referrer Policy:no-referrer-when-downgrade
I have tried to replace the url in my configs to an entirely different url / api.
the api is a mock data api https://jsonplaceholder.typicode.com
In this case I am requesting:
`/comments/1’
and that is being finally requested in the browser as:
Request URL:http://localhost:8100/comments/1 Request Method:GET Status Code:304 Not Modified Remote Address:127.0.0.1:8100 Referrer Policy:no-referrer-when-downgrade
my proxy is : { "path": "/comments", "proxyUrl": "https://jsonplaceholder.typicode.com/comments" }
oddly though the request to /comments does return a result.
so why do you think it does not work with https://api.coinmarketcap.com/v1? the pattern is the same.
EDIT: I’m seeing that there is a 301 response in the "/v1/ticker" request:
Request URL:http://localhost:8100/v1/ticker Request Method:GET Status Code:301 Moved Permanently (from disk cache) Remote Address:127.0.0.1:8100 Referrer Policy:no-referrer-when-downgrade
Request Headers Provisional headers are shown Accept:application/json, text/plain, */* Referer:http://localhost:8100/ User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/61.0.3163.100 Safari/537.36`
Is this confirming a problem with the service api.coinmarketcap?
After trying other API’s I belive that it was an issue with the specific API api.coinmarketcap. I wonder why that is though… Thanks for your help @Ben1nB1ack
Unbelievably, your configuration does not work on my end, and I copied your proxy and request exactly. I am still getting the 301:
Request URL:http://localhost:8100/cm/v1/ticker Request Method:GET Status Code:301 Moved Permanently (from disk cache)
followed by the 401:
Request URL:http://localhost:8100/v1/ticker/ Request Method:GET Status Code:404 Not Found Remote Address:127.0.0.1:8100 Referrer Policy:no-referrer-when-downgrade
EDIT: that is, I tried the configuration in my current project, I’m not sure what would happen if I started a new project. I will try that now.
I created a new ionic project with the simplest possible configuration and it worked fine. I was able to get data from the request. I’ll have to look into this further.