Code Monkey home page Code Monkey logo

rack-jsonp-middleware's Introduction

rack-jsonp-middleware

Travis CI Status - Gemnasium Dependencies Status - Code Climate

Rack middleware that turns all .jsonp requests into a jsonp response.

Overview

(does not support 'callback' since it is a really generic parameter name)

Btw, don't forget to give a try to J50Nฯ€ (a pure JS JSONP helper), they make a lovely couple together :P

Authors

Roberto Decurnex ([email protected])

Contributors

Install

If you are using Bundler you can easily add the following line to your Gemfile:

gem 'rack-jsonp-middleware'

Or you can just install it as a ruby gem by running:

$ gem install rack-jsonp-middleware

Configuration

Rails 3

In your config/application.rb file add:

require 'rack/jsonp'

And, within the config block:

config.middleware.use Rack::JSONP

Here is an exelent example of this - Rails 3 Configuration Example

Thank you rwilcox!

Rails 2

Same as for Rails 3 but modifying the config/environment.rb file instead.

Rack Apps

In your config.ru file add the following lines:

require 'rack/jsonp'
use Rack::JSONP

Download

You can also clone the project with Git by running: $ git clone git://github.com/robertodecurnex/rack-jsonp-middleware

Examples

Given that http://domain.com/action.json returns:

{"key":"value"}

With the following Content-Type:

application/json

Then http://domain.com/action.jsonp?callback=J50Npi.success will return:

J50Npi.success({"key":"value"})

With the following Content-Type:

application/javascript

But http://domain.com/action.json?callback=J50Npi.sucess will still return:

{"key":"value"}

With the following Content-Type:

application/json

Security

Supporting jsonp means that another websites can access your website on behalf of a user visiting their site, which might lead to security problems (e.g. they read http://yoursite.com/user.jsonp and get the users email etc), so think about if you want to turn it on globally.

rack-jsonp-middleware's People

Contributors

grosser avatar mikeemery avatar mzsanford avatar robertodecurnex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.