rack-cors
rack-cors copied to clipboard
CORS headers are being returned for non-CORS OPTIONS requests
This OPTIONS request in this comment should not be returning CORS headers: https://github.com/cyu/rack-cors/issues/20#issuecomment-46523416
I was able to fix this issue by only returning headers instead of redirecting. This was accomplished in my Rails API by placing the following code in my create action:
def create
@passage = Passage.new(passage_params)
respond_to do |format|
if @passage.save
# formatting this way is required for Angularjs app to not return a http 406 status
format.html do
head 200, content_type: "text/plain"
end
format.json { render json: @passage.to_json }
# previous code is commented out in the following 2 lines
# format.html { redirect_to @passage, notice: 'Passage was successfully created.' }
# format.json { render :show, status: :created, location: @passage }
else
format.html { render :new }
format.json { render json: @passage.errors, status: :unprocessable_entity }
end
end
end
See my post here for additional details: http://stackoverflow.com/q/26977623/964018