Commit fcdedb8abdf9393177a80934d58c4e152eab6071
1 parent
c70ebb73
Exists in
master
and in
1 other branch
fixes #970 add cors headers once again
Showing
2 changed files
with
9 additions
and
0 deletions
Show diff stats
app/controllers/api/v3/notices_controller.rb
@@ -5,6 +5,9 @@ class Api::V3::NoticesController < ApplicationController | @@ -5,6 +5,9 @@ class Api::V3::NoticesController < ApplicationController | ||
5 | respond_to :json | 5 | respond_to :json |
6 | 6 | ||
7 | def create | 7 | def create |
8 | + response.headers['Access-Control-Allow-Origin'] = '*' | ||
9 | + response.headers['Access-Control-Allow-Headers'] = 'origin, content-type, accept' | ||
10 | + | ||
8 | params.merge!(JSON.parse(request.raw_post) || {}) | 11 | params.merge!(JSON.parse(request.raw_post) || {}) |
9 | report = AirbrakeApi::V3::NoticeParser.new(params).report | 12 | report = AirbrakeApi::V3::NoticeParser.new(params).report |
10 | 13 |
spec/controllers/api/v3/notices_controller_spec.rb
@@ -6,6 +6,12 @@ describe Api::V3::NoticesController, type: :controller do | @@ -6,6 +6,12 @@ describe Api::V3::NoticesController, type: :controller do | ||
6 | Rails.root.join('spec', 'fixtures', 'api_v3_request.json').read | 6 | Rails.root.join('spec', 'fixtures', 'api_v3_request.json').read |
7 | end | 7 | end |
8 | 8 | ||
9 | + it 'sets CORS headers on POST request' do | ||
10 | + post :create, project_id: 'invalid id' | ||
11 | + expect(response.headers['Access-Control-Allow-Origin']).to eq('*') | ||
12 | + expect(response.headers['Access-Control-Allow-Headers']).to eq('origin, content-type, accept') | ||
13 | + end | ||
14 | + | ||
9 | it 'returns created notice id in json format' do | 15 | it 'returns created notice id in json format' do |
10 | post :create, legit_body, legit_params | 16 | post :create, legit_body, legit_params |
11 | notice = Notice.last | 17 | notice = Notice.last |