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

Set custom URL on the REST adapter #249

Merged
merged 1 commit into from Oct 18, 2012

Conversation

Projects
None yet
8 participants
@jfturcot
Contributor

jfturcot commented May 8, 2012

This lets you set a custom URL to be able to fetch data from an external API or a url with a different subdomain.

@boy-jer

This comment has been minimized.

Show comment
Hide comment
@boy-jer

boy-jer May 11, 2012

+1, this sounds good for anyone implementing saas apps that ties new acounts to subdomains.

boy-jer commented May 11, 2012

+1, this sounds good for anyone implementing saas apps that ties new acounts to subdomains.

@agnessa

This comment has been minimized.

Show comment
Hide comment
@agnessa

agnessa May 17, 2012

Is this actually enough to enable cross domain requests? I tried this out but couldn't get it to work -- an OPTIONS request is issued to the backend, which then returns with 200 OK and proper access headers. Then nothing happens, so the data is not fetched... No error message either. Do you have a working example you could share? Thank you!

agnessa commented on cb64a28 May 17, 2012

Is this actually enough to enable cross domain requests? I tried this out but couldn't get it to work -- an OPTIONS request is issued to the backend, which then returns with 200 OK and proper access headers. Then nothing happens, so the data is not fetched... No error message either. Do you have a working example you could share? Thank you!

This comment has been minimized.

Show comment
Hide comment
@jfturcot

jfturcot May 17, 2012

Owner

You have to setup CORS on your server, in my project I use Rails with the rack-cors gem to take care of CORS in a middleware. If you are not familiar with CORS, it is a way to tell the browser that your server accepts XHR requests coming from other domains. By default and for security reason the browser does not let you do XHR requests to other domains.

The following is what I have to configure rack-cors in config/application.rb

config.middleware.use Rack::Cors do                                                                                                  
  allow do                                                                                                                           
    origins '*'                                                                                                                   
    resource '*',                                                                                                                    
    headers: ['Origin', 'Accept', 'Content-Type', 'X-CSRF-Token'],                                                                 
    methods: [:get, :post, :put, :delete]                                                                                          
  end                                                                                                                                
end

Security wise, its a pretty bad idea to use this because I am accepting any other domains, but I am still in development and I will tighten this up later.

I hope this helps.

Owner

jfturcot replied May 17, 2012

You have to setup CORS on your server, in my project I use Rails with the rack-cors gem to take care of CORS in a middleware. If you are not familiar with CORS, it is a way to tell the browser that your server accepts XHR requests coming from other domains. By default and for security reason the browser does not let you do XHR requests to other domains.

The following is what I have to configure rack-cors in config/application.rb

config.middleware.use Rack::Cors do                                                                                                  
  allow do                                                                                                                           
    origins '*'                                                                                                                   
    resource '*',                                                                                                                    
    headers: ['Origin', 'Accept', 'Content-Type', 'X-CSRF-Token'],                                                                 
    methods: [:get, :post, :put, :delete]                                                                                          
  end                                                                                                                                
end

Security wise, its a pretty bad idea to use this because I am accepting any other domains, but I am still in development and I will tighten this up later.

I hope this helps.

This comment has been minimized.

Show comment
Hide comment
@agnessa

agnessa replied May 17, 2012

thanks!

@wagenet

This comment has been minimized.

Show comment
Hide comment
@wagenet

wagenet Jun 21, 2012

Member

This seems ok. @wycats, @tomdale?

Member

wagenet commented Jun 21, 2012

This seems ok. @wycats, @tomdale?

@tkellen

This comment has been minimized.

Show comment
Hide comment
@tkellen

tkellen Jul 3, 2012

Just chiming in to say that this would be nice to have.

tkellen commented Jul 3, 2012

Just chiming in to say that this would be nice to have.

@karlfreeman

This comment has been minimized.

Show comment
Hide comment
@karlfreeman

karlfreeman commented Jul 4, 2012

👍

@nfedyashev

This comment has been minimized.

Show comment
Hide comment
@nfedyashev

nfedyashev Aug 4, 2012

Isn't it confusing to have both options: namespace and url in RESTAdapter?
Perhaps hostname would be a better option name instead of url in this case?

Or both options could be merged into single url to eliminate this confusion.

What do you think guys?

nfedyashev commented Aug 4, 2012

Isn't it confusing to have both options: namespace and url in RESTAdapter?
Perhaps hostname would be a better option name instead of url in this case?

Or both options could be merged into single url to eliminate this confusion.

What do you think guys?

@jfturcot

This comment has been minimized.

Show comment
Hide comment
@jfturcot

jfturcot Aug 5, 2012

Contributor

I agree with you, I used url because it was an already used variable in the buildURL function, but I guess that namespace could become url.

Contributor

jfturcot commented Aug 5, 2012

I agree with you, I used url because it was an already used variable in the buildURL function, but I guess that namespace could become url.

@julianalucena

This comment has been minimized.

Show comment
Hide comment
@julianalucena

julianalucena Sep 15, 2012

It would be really nice.

julianalucena commented Sep 15, 2012

It would be really nice.

wagenet added a commit that referenced this pull request Oct 18, 2012

Merge pull request #249 from jfturcot/rest_custom_url
Set custom URL on the REST adapter

@wagenet wagenet merged commit 35f66f1 into emberjs:master Oct 18, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment