Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow CORS?

  • Loading branch information...
commit d3040106de8ea43b8b1b13908e84eafd05018c2e 1 parent e1acc96
@ajb authored
Showing with 25 additions and 3 deletions.
  1. +25 −3 app/controllers/stations_controller.rb
View
28 app/controllers/stations_controller.rb
@@ -1,6 +1,28 @@
- class StationsController < ApplicationController
- # GET /stations
- # GET /stations.json
+class StationsController < ApplicationController
+
+ before_filter :cors_preflight_check
+ after_filter :cors_set_access_control_headers
+
+ def cors_set_access_control_headers
+ headers['Access-Control-Allow-Origin'] = '*'
+ headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
+ headers['Access-Control-Max-Age'] = "1728000"
+ end
+
+ # If this is a preflight OPTIONS request, then short-circuit the
+ # request, return only the necessary headers and return an empty
+ # text/plain.
+
+ def cors_preflight_check
+ if request.method == :options
+ headers['Access-Control-Allow-Origin'] = '*'
+ headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
+ headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version'
+ headers['Access-Control-Max-Age'] = '1728000'
+ render :text => '', :content_type => 'text/plain'
+ end
+ end
+
def index
if params[:lat] && params[:lng]
@stations = Station.near([params[:lat], params[:lng]], 200)
Please sign in to comment.
Something went wrong with that request. Please try again.