Closed brandonhilkert closed 9 years ago
Let's take an example...
Let's say http://www.example.com/api/v1/posts/1.json
is the call your Ember CLI application makes. But, you want to proxy that request to another server so as to avoid CORS.
If you're deploying it to Heroku with this buildpack you need to set two things. First, set an API proxy URL:
$ heroku config:set API_URL=http://api.example.com/
This is the URL to the desired API server.
Next, set your API's prefix path (Default: /api/
):
$ heroku config:set API_PREFIX_PATH=/api/
Now, all requests local to your Ember CLI application that start with that prefix, in this case /api/
, will be proxied to that API_URL
server.
Note: The /api/
is stripped from the request. The way to get around this is to remember that the API_URL
is a full URL. So, if you want to keep the /api/
within the path of the proxied request, you can set the API_URL
to:
$ heroku config:set API_URL=http://api.example.com/api/
Cool thanks for the insight!
I'm going to move this into a Wiki page soon :)
Can you suggest a good approach for managing an API URL?
I've been testing with the
--proxy
option with ember serve and it works well. I tried to useAPI_URL
and read the issues about it not using/api/
, but the app doesn't even seem like it's directing the model calls to the API. Is this setup expecting the app to set the host in the adapter?Just need a little guidance, I'm new to this. Thanks!