Using Batman Across Subdomains

78 views
Skip to first unread message

phil...@gmail.com

unread,
Aug 5, 2012, 5:07:12 PM8/5/12
to batm...@googlegroups.com
Hello,

I have an api that I would like to consume using Batman. It's a rails app running on api.foo.bar and the batman site would be running on foo.bar. Is it possible to configure Batman to point to api.foo.bar? It looks like it always defaults to the current url and I haven't been able to find a way to override that.

Thanks for your help
-Mike

Nick Small

unread,
Aug 8, 2012, 5:17:02 PM8/8/12
to batm...@googlegroups.com, phil...@gmail.com
Hey Mike,

There's a few things to note here. First, you can override the URL of a model with `url:` and define it as either a function or a string. You can also override `urlPrefix` to just add a prefix to the default URL's.

That said, you're going to run into same origin issues. One way around them is to use JSONP, which you can do by telling your Batman.Requests to use `type: jsonp`. However JSONP only works with GET requests, so that probably won't work.

The other options are to run them on the same domain, or run all your requests through a proxy server. At that point, the default URL's should work fine for you.

Hope that helps,

–Nick

Mike Emery

unread,
Aug 8, 2012, 5:18:01 PM8/8/12
to Nick Small, batm...@googlegroups.com
Thanks for the help, I will play around with your suggestions.

-- 
Mike Emery
Sent with Sparrow

Conrad Decker

unread,
Aug 12, 2012, 6:11:45 PM8/12/12
to batm...@googlegroups.com, Nick Small, phil...@gmail.com
I *believe* you may also be able to utilize CORS to handle calls across different domains. If you have control over api.foo.bar and are able to add headers to your HTTP Responses you may be in luck. 

You can take a look here and here for some more information. That said, I haven't actually tried to implement it so I'm not sure how easy it is :) 

Would love to hear how you make out though if you head down that road. 

Cheers!

ryker...@gmail.com

unread,
Dec 4, 2014, 5:54:33 PM12/4/14
to batm...@googlegroups.com, phil...@gmail.com
I know this is super old and batman is no longer supported, but did you figure this out? I'm trying to do something similar, but haven't figured out how

Mike Emery

unread,
Dec 5, 2014, 2:12:14 AM12/5/14
to ryker...@gmail.com, batm...@googlegroups.com

I never did, no

conrad...@gmail.com

unread,
Dec 5, 2014, 8:30:14 AM12/5/14
to batm...@googlegroups.com, phil...@gmail.com, ryker...@gmail.com
I was eventually able to get this working. Essentially, you need to set @urlPrefix as well as urlPrefix in your Model.

Here's a thread that helped me when I was looking to do the same: https://groups.google.com/forum/#!topic/batmanjs/ILmsYrTwIQw as well as a GitHub issue that I opened that has an explanation as to why: https://github.com/batmanjs/batman/issues/620

Hope that helps.
Reply all
Reply to author
Forward
0 new messages