From 0527e1fa49b096fd8ce2d1080323854448f8cee0 Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Wed, 27 Sep 2017 15:43:54 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Remove=20NewRelicRPM=20-=20we=20don?= =?UTF-8?q?=E2=80=99t=20use=20it=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 - Gemfile.lock | 2 -- lib/bandiera.rb | 1 - 3 files changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index 1553d49..74952f4 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,6 @@ gem 'puma', require: false gem 'airbrake', require: false gem 'statsd-ruby', require: false -gem 'newrelic_rpm' group :development do gem 'shotgun' diff --git a/Gemfile.lock b/Gemfile.lock index 264060e..c15a206 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,7 +81,6 @@ GEM mustermann (1.0.1) mysql2 (0.4.9) nenv (0.3.0) - newrelic_rpm (4.4.0.336) nokogiri (1.8.1) mini_portile2 (~> 2.3.0) nokogiri (1.8.1-java) @@ -200,7 +199,6 @@ DEPENDENCIES lru_redux macmillan-utils mysql2 - newrelic_rpm pg poltergeist pry diff --git a/lib/bandiera.rb b/lib/bandiera.rb index fa8a298..dd4f9d4 100644 --- a/lib/bandiera.rb +++ b/lib/bandiera.rb @@ -3,7 +3,6 @@ require 'sequel' require 'macmillan/utils/logger' require_relative 'hash' -require 'newrelic_rpm' GC::Profiler.enable From 8499021b5559327f1c969161cedfa5683c7895f7 Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Wed, 27 Sep 2017 15:46:19 +0100 Subject: [PATCH 2/2] Allow CORS (cross-site javascript) requests to the v2 API This change enables users to allow CORS requests to the v2 API on a Bandier instance - they just need to set the allowed calling domains via an environment variable. --- Gemfile | 1 + Gemfile.lock | 2 ++ config.ru | 13 ++++++++++++- docker-compose.yml | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 74952f4..cbcd708 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ gem 'puma', require: false gem 'airbrake', require: false gem 'statsd-ruby', require: false +gem 'rack-cors' group :development do gem 'shotgun' diff --git a/Gemfile.lock b/Gemfile.lock index c15a206..7fdf979 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,7 @@ GEM puma (3.10.0) puma (3.10.0-java) rack (2.0.3) + rack-cors (1.0.1) rack-flash3 (1.0.5) rack rack-protection (2.0.0) @@ -203,6 +204,7 @@ DEPENDENCIES poltergeist pry puma + rack-cors rack-flash3 rack-test rake diff --git a/config.ru b/config.ru index 5d5b6ed..45382ae 100644 --- a/config.ru +++ b/config.ru @@ -19,9 +19,20 @@ if ENV['AIRBRAKE_API_KEY'] && ENV['AIRBRAKE_PROJECT_ID'] end end -require 'macmillan/utils/statsd_middleware' +if ENV['RACK_CORS_ORIGINS'] + require 'rack/cors' + use Rack::Cors do + allow do + origins ENV['RACK_CORS_ORIGINS'] + resource '/api/v2/*', headers: :any, methods: [:get, :options] + end + end +end + +require 'macmillan/utils/statsd_middleware' use Macmillan::Utils::StatsdMiddleware, client: Bandiera.statsd + use Rack::CommonLogger, Bandiera.logger use Airbrake::Rack::Middleware if ENV['AIRBRAKE_API_KEY'] && ENV['AIRBRAKE_PROJECT_ID'] diff --git a/docker-compose.yml b/docker-compose.yml index f6cdc72..303bba1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: RACK_ENV: 'development' DATABASE_URL: 'postgres://bandiera:bandiera@db/bandiera' LOG_TO_STDOUT: 'true' + RACK_CORS_ORIGINS: '*' links: - db