From fcdedb8abdf9393177a80934d58c4e152eab6071 Mon Sep 17 00:00:00 2001 From: Stephen Crosby Date: Wed, 14 Oct 2015 17:44:39 -0700 Subject: [PATCH] fixes #970 add cors headers once again --- app/controllers/api/v3/notices_controller.rb | 3 +++ spec/controllers/api/v3/notices_controller_spec.rb | 6 ++++++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/app/controllers/api/v3/notices_controller.rb b/app/controllers/api/v3/notices_controller.rb index 57637b4..ab3f4f5 100644 --- a/app/controllers/api/v3/notices_controller.rb +++ b/app/controllers/api/v3/notices_controller.rb @@ -5,6 +5,9 @@ class Api::V3::NoticesController < ApplicationController respond_to :json def create + response.headers['Access-Control-Allow-Origin'] = '*' + response.headers['Access-Control-Allow-Headers'] = 'origin, content-type, accept' + params.merge!(JSON.parse(request.raw_post) || {}) report = AirbrakeApi::V3::NoticeParser.new(params).report diff --git a/spec/controllers/api/v3/notices_controller_spec.rb b/spec/controllers/api/v3/notices_controller_spec.rb index 920de59..1a3e46c 100644 --- a/spec/controllers/api/v3/notices_controller_spec.rb +++ b/spec/controllers/api/v3/notices_controller_spec.rb @@ -6,6 +6,12 @@ describe Api::V3::NoticesController, type: :controller do Rails.root.join('spec', 'fixtures', 'api_v3_request.json').read end + it 'sets CORS headers on POST request' do + post :create, project_id: 'invalid id' + expect(response.headers['Access-Control-Allow-Origin']).to eq('*') + expect(response.headers['Access-Control-Allow-Headers']).to eq('origin, content-type, accept') + end + it 'returns created notice id in json format' do post :create, legit_body, legit_params notice = Notice.last -- libgit2 0.21.2