From 666ce5515732554769af38a50f32f02cb94b2891 Mon Sep 17 00:00:00 2001 From: Stephen Crosby Date: Thu, 4 Feb 2016 17:11:30 -0800 Subject: [PATCH] #1044 support and document the airbrake-js xhr reporter --- README.md | 15 +++++++++------ app/controllers/api/v3/notices_controller.rb | 1 + config/routes.rb | 2 +- spec/controllers/api/v3/notices_controller_spec.rb | 6 ++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4461190..528e9cc 100644 --- a/README.md +++ b/README.md @@ -243,17 +243,20 @@ This tab will be hidden if no user information is available. Javascript error notifications -------------------------------------- - You can log javascript errors that occur in your application by including the [airbrake-js](https://github.com/airbrake/airbrake-js) javascript library. -Install airbrake-js according to the docs at -[airbrake-js](https://github.com/airbrake/airbrake-js) and set your project and -host as early as possible: +Install airbrake-js according to the docs at and set your project and host as +soon as you want to start reporting errors. Then follow along with the +documentation at https://github.com/airbrake/airbrake-js/blob/master/README.md ```javascript -Airbrake.setProject("ERRBIT API KEY", "ERRBIT API KEY"); -Airbrake.setHost("http://errbit.yourdomain.com"); +var airbrake = new airbrakeJs.Client({ + projectId: 'ERRBIT API KEY', + projectKey: 'ERRBIT API KEY (again)', + reporter: 'xhr', + host: 'https://myerrbit.com' +}); ``` Plugins and Integrations diff --git a/app/controllers/api/v3/notices_controller.rb b/app/controllers/api/v3/notices_controller.rb index f344eb4..a1a492f 100644 --- a/app/controllers/api/v3/notices_controller.rb +++ b/app/controllers/api/v3/notices_controller.rb @@ -10,6 +10,7 @@ class Api::V3::NoticesController < ApplicationController def create response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Access-Control-Allow-Headers'] = 'origin, content-type, accept' + return render(status: 200, text: '') if request.method == 'OPTIONS' report = AirbrakeApi::V3::NoticeParser.new( params.merge(JSON.parse(request.raw_post) || {})).report diff --git a/config/routes.rb b/config/routes.rb index a0c7a82..c439c90 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,7 +64,7 @@ Rails.application.routes.draw do end match '/api/v3/projects/:project_id/create-notice' => 'api/v3/notices#create', via: [:post] - match '/api/v3/projects/:project_id/notices' => 'api/v3/notices#create', via: [:post] + match '/api/v3/projects/:project_id/notices' => 'api/v3/notices#create', via: [:post, :options] root to: 'apps#index' end diff --git a/spec/controllers/api/v3/notices_controller_spec.rb b/spec/controllers/api/v3/notices_controller_spec.rb index fa3541f..d197eee 100644 --- a/spec/controllers/api/v3/notices_controller_spec.rb +++ b/spec/controllers/api/v3/notices_controller_spec.rb @@ -12,6 +12,12 @@ describe Api::V3::NoticesController, type: :controller do expect(response.headers['Access-Control-Allow-Headers']).to eq('origin, content-type, accept') end + it 'responds to an OPTIONS request' do + process :create, 'OPTIONS', project_id: 'nothingspecial' + 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