JSONP support

10 views
Skip to first unread message

Nick Gorbikoff

unread,
Oct 27, 2014, 4:37:32 PM10/27/14
to praxis-...@googlegroups.com
Hello.

Trying to send a JSONP request I get this error

callbackName (
{"name": "ValidationError","message": "Unknown attributes received: [:callback, :_] while loading $.params"}
)


I have added rack & rack/contrib to my Gemfile

gem 'rack', '~> 1.0'
gem 'rack-contrib', require: 'rack/contrib'



And in my config.ru

use Rack::JSONP



According to https://github.com/rack/rack-contrib  - that's all I need to do. I can check for callback param in each of my resourse definitions, but I shouldn't really have to?

The app is internal but the client app is loaded from myapp.example.com while api resides on api.example.com


Nick Gorbikoff

unread,
Oct 27, 2014, 4:45:14 PM10/27/14
to praxis-...@googlegroups.com
I guess the question is not what's wrong with my setup so much , but rather  if anyone already did a jsonp setup with praxis - how did you set it up?

Josep Blanquer

unread,
Oct 27, 2014, 10:23:17 PM10/27/14
to Nick Gorbikoff, praxis-...@googlegroups.com
Nick,

 To use JSONP calls you pass the "callback" param in the query string. So, since Praxis does not know anything about that (or JSONP for that matter), he expects that parameter to be defined for all the actions that you allow it on. Obviously that's not optimal, but, strictly speaking that would solve your problem at hand.

One  way to do that would be to build a trait, and include it at the top of every resource definition (so that all actions will inherit it)

Another "hacky", but perhaps simpler, approach for now can be to build or monkey-patch the rack JSONP middleware so that it "deletes" that parameter from the 'env' after it uses it. That would keep Praxis happy (since it won't see it) but it is not a good solution since nothing in the documentation would know about the jsonp support. Again, it would make it work, but not great.
  1. BTW: another way to avoid monkey patching would be a add another "lambda-type" middleware (added after JSONP) that simply deletes the "callback" key from the env.
Note: I am not sure what the ":_" extra param you're pasting above...I'm assuming that's just a test you have passing that key?...

Now... about the "real/better" way to fix it...:
  • We are in the middle of building/designing the Plugin architecture for Praxis, and as such we'll create more flexibility to connect other pieces of software into your app...which includes middleware of sorts. For example, we could allow you to add straight middleware pieces into the app, rather than doing it with a builder outside the inner app.  This would allow us/you to trivially create a JSON Plugin that adds an existing middleware (rack jsonp) into your app and adds other hooks such as automatically creating params for all your resources/actions and even create hooks into document generation understanding its semantics...etc.
Anyway, so, you'd need to "hack it in" for how but better support for such things is on the way. (We can probably share some initial thoughts with the list soon, to see what everybody else thinks).

Cheers,

Josep M.


--
You received this message because you are subscribed to the Google Groups "praxis-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to praxis-suppor...@googlegroups.com.
To post to this group, send email to praxis-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/praxis-support/ad676e62-b9a1-40b8-afc4-c6039a8504ce%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nick Gorbikoff

unread,
Oct 27, 2014, 10:40:49 PM10/27/14
to Josep Blanquer, praxis-...@googlegroups.com
Josep thanks for looking into it
For now I just solved it by adding rack cors to config.ru and limiting to allow through all clients on local subnet


Sent from my iPhone

> On Oct 27, 2014, at 21:23, Josep Blanquer <blan...@rightscale.com> wrote:
>
>
Reply all
Reply to author
Forward
0 new messages